コード例 #1
0
ファイル: github_test.go プロジェクト: toggl/gomniauth
func TestGitHubGetBeginAuthURL(t *testing.T) {

	common.SetSecurityKey("ABC123")

	state := &common.State{Map: objx.MSI("after", "http://www.stretchr.com/")}

	g := New("clientID", "secret", "http://myapp.com/")

	url, err := g.GetBeginAuthURL(state, nil)

	if assert.NoError(t, err) {
		assert.Contains(t, url, "client_id=clientID")
		assert.Contains(t, url, "redirect_uri=http%3A%2F%2Fmyapp.com%2F")
		assert.Contains(t, url, "scope="+githubDefaultScope)
		assert.Contains(t, url, "access_type="+oauth2.OAuth2AccessTypeOnline)
		assert.Contains(t, url, "approval_prompt="+oauth2.OAuth2ApprovalPromptAuto)
	}

	state = &common.State{Map: objx.MSI("after", "http://www.stretchr.com/")}

	g = New("clientID", "secret", "http://myapp.com/")

	url, err = g.GetBeginAuthURL(state, objx.MSI(oauth2.OAuth2KeyScope, "avatar"))

	if assert.NoError(t, err) {
		assert.Contains(t, url, "client_id=clientID")
		assert.Contains(t, url, "redirect_uri=http%3A%2F%2Fmyapp.com%2F")
		assert.Contains(t, url, "scope=avatar+"+githubDefaultScope)
		assert.Contains(t, url, "access_type="+oauth2.OAuth2AccessTypeOnline)
		assert.Contains(t, url, "approval_prompt="+oauth2.OAuth2ApprovalPromptAuto)
	}

}
コード例 #2
0
ファイル: url_test.go プロジェクト: toggl/gomniauth
func TestOAuth2HandlerBeginAuthURLWithBaseWithoutState(t *testing.T) {

	common.SetSecurityKey("rAALj6QhRjsTo3VKzfWuK21qNZ5bFfqPJ9sYNerSYeKKoMIPAi9vaIusjmqyLE3S")

	base := "https://base.url/auth"

	config := &common.Config{Map: objx.MSI()}
	config.
		Set("client_id", "client_id").
		Set("redirect_uri", "redirect_uri").
		Set("scope", "scope").
		Set("access_type", "access_type").
		Set("approval_prompt", "approval_prompt")

	url, err := GetBeginAuthURLWithBase(base, nil, config)

	if assert.NoError(t, err) {
		assert.Contains(t, url, "client_id=client_id")
		assert.Contains(t, url, "redirect_uri=redirect_uri")
		assert.Contains(t, url, "scope=scope")
		assert.Contains(t, url, "access_type=access_type")
		assert.Contains(t, url, "approval_prompt=approval_prompt")
		assert.NotContains(t, url, "state=")
	}

}
コード例 #3
0
ファイル: url_test.go プロジェクト: toggl/gomniauth
func TestOAuth2HandlerBeginAuthURLWithBaseMultipleScope(t *testing.T) {

	common.SetSecurityKey("rAALj6QhRjsTo3VKzfWuK21qNZ5bFfqPJ9sYNerSYeKKoMIPAi9vaIusjmqyLE3S")

	base := "https://base.url/auth"

	config := &common.Config{Map: objx.MSI()}
	config.
		Set("client_id", "client_id").
		Set("redirect_uri", "redirect_uri").
		Set("scope", "scope1 scope2").
		Set("access_type", "access_type").
		Set("approval_prompt", "approval_prompt")

	state := &common.State{Map: objx.MSI("after", "http://www.stretchr.com/")}
	base64State, _ := state.Base64()

	url, err := GetBeginAuthURLWithBase(base, state, config)

	if assert.NoError(t, err) {
		assert.Contains(t, url, "client_id=client_id")
		assert.Contains(t, url, "redirect_uri=redirect_uri")
		assert.Contains(t, url, "scope=scope1+scope2")
		assert.Contains(t, url, "access_type=access_type")
		assert.Contains(t, url, "approval_prompt=approval_prompt")
		assert.Contains(t, url, "state="+base64State)
	}

}
コード例 #4
0
ファイル: google_test.go プロジェクト: toggl/gomniauth
func TestGitHubGetBeginAuthURL(t *testing.T) {

	common.SetSecurityKey("ABC123")

	state := &common.State{Map: objx.MSI("after", "http://www.stretchr.com/")}

	g := New("clientID", "secret", "http://myapp.com/")

	url, err := g.GetBeginAuthURL(state, nil)

	if assert.NoError(t, err) {
		assert.Contains(t, url, "client_id=clientID")
		assert.Contains(t, url, "redirect_uri=http%3A%2F%2Fmyapp.com%2F")
		assert.Contains(t, url, "scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com")
		assert.Contains(t, url, "access_type="+oauth2.OAuth2AccessTypeOnline)
		assert.Contains(t, url, "approval_prompt="+oauth2.OAuth2ApprovalPromptAuto)
	}

}
コード例 #5
0
ファイル: provider_list_test.go プロジェクト: toggl/gomniauth
func TestWithProviders(t *testing.T) {

	common.SetSecurityKey("ABC123")

	prov1 := new(test.TestProvider)
	prov2 := new(test.TestProvider)

	list := WithProviders(prov1, prov2)

	if assert.NotNil(t, list) {

		if assert.Equal(t, 2, len(list.providers)) {
			assert.Equal(t, prov1, list.providers[0])
			assert.Equal(t, prov2, list.providers[1])
		}

		// make sure the SharedProviderList was assigned too
		assert.Equal(t, SharedProviderList, list)

	}

}
コード例 #6
0
ファイル: security.go プロジェクト: toggl/gomniauth
// SetSecurityKey sets the global security key to be used for signing the state variable
// in the auth request. This allows gomniauth to detect if the data in the
// state variable has been changed.
func SetSecurityKey(key string) {
	common.SetSecurityKey(key)
}