本文整理汇总了Golang中github.com/toggl/gomniauth/common.Credentials类的典型用法代码示例。如果您正苦于以下问题:Golang Credentials类的具体用法?Golang Credentials怎么用?Golang Credentials使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Credentials类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewUser
// NewUser builds a new User object for Github.
func NewUser(data objx.Map, creds *common.Credentials, provider common.Provider) *User {
user := &User{data}
creds.Set(common.CredentialsKeyID, data[spotifyKeyID])
// set provider credentials
user.data[common.UserKeyProviderCredentials] = map[string]*common.Credentials{
provider.Name(): creds,
}
return user
}
示例2: TestOAuth2Provider_CompleteAuth_JSON
func TestOAuth2Provider_CompleteAuth_JSON(t *testing.T) {
config := &common.Config{
Map: objx.MSI(
OAuth2KeyRedirectUrl, OAuth2KeyRedirectUrl,
OAuth2KeyScope, OAuth2KeyScope,
OAuth2KeyClientID, OAuth2KeyClientID,
OAuth2KeySecret, OAuth2KeySecret,
OAuth2KeyAuthURL, OAuth2KeyAuthURL,
OAuth2KeyTokenURL, OAuth2KeyTokenURL)}
testTripperFactory := new(test.TestTripperFactory)
testTripper := new(test.TestTripper)
testProvider := new(test.TestProvider)
creds := new(common.Credentials)
testResponse := new(http.Response)
testResponse.Header = make(http.Header)
testResponse.Header.Set("Content-Type", "application/json")
testResponse.StatusCode = 200
testResponse.Body = ioutil.NopCloser(strings.NewReader(`{"expires_in":20,"access_token":"ACCESSTOKEN","refresh_token":"REFRESHTOKEN"}`))
testTripperFactory.On("NewTripper", common.EmptyCredentials, mock.Anything).Return(testTripper, nil)
testTripper.On("RoundTrip", mock.Anything).Return(testResponse, nil)
data := objx.MSI(OAuth2KeyCode, []string{"123"})
creds, err := CompleteAuth(testTripperFactory, data, config, testProvider)
if assert.NoError(t, err) {
if assert.NotNil(t, creds, "Creds should be returned") {
assert.Equal(t, creds.Get(OAuth2KeyAccessToken).Str(), "ACCESSTOKEN")
assert.Equal(t, creds.Get(OAuth2KeyRefreshToken).Str(), "REFRESHTOKEN")
assert.Equal(t, creds.Get(OAuth2KeyExpiresIn).Data().(time.Duration), time.Duration(20)*time.Second)
}
}
mock.AssertExpectationsForObjects(t, testTripperFactory.Mock, testTripper.Mock, testProvider.Mock)
}
示例3: AuthorizationHeader
// AuthorizationHeader returns the key, value pair to insert into an authorized request.
func AuthorizationHeader(creds *common.Credentials) (key, value string) {
return "Authorization", "Bearer " + creds.Get(OAuth2KeyAccessToken).Str("Invalid")
}