Skip to content

Commit

Permalink
add NewClientTokenJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
grokify committed Apr 23, 2018
1 parent bd3a44a commit 5e5d9f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
9 changes: 4 additions & 5 deletions google/google_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@ func NewClientSvcAccountFromFile(ctx context.Context, svcAccountConfigFile strin
if err != nil {
return nil, err
}
return NewClientSvcAccountFromJSON(ctx, svcAccountConfig, scopes...)
return NewClientFromJWTJSON(ctx, svcAccountConfig, scopes...)
}

func NewClientSvcAccountFromJSON(ctx context.Context, svcAccountConfig []byte, scopes ...string) (*http.Client, error) {
conf, err := google.JWTConfigFromJSON(svcAccountConfig, scopes...)
func NewClientFromJWTJSON(ctx context.Context, svcAccountConfig []byte, scopes ...string) (*http.Client, error) {
jwtConf, err := google.JWTConfigFromJSON(svcAccountConfig, scopes...)
if err != nil {
return nil, err
}
client := conf.Client(ctx)
return client, nil
return jwtConf.Client(ctx), nil
}
12 changes: 12 additions & 0 deletions oauth2more.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ func NewClientAuthCode(conf oauth2.Config, authCode string) (*http.Client, error
return conf.Client(oauth2.NoContext, token), nil
}

func NewClientTokenJSON(ctx context.Context, tokenJSON []byte) (*http.Client, error) {
token := &oauth2.Token{}
err := json.Unmarshal(tokenJSON, token)
if err != nil {
return nil, err
}

oAuthConfig := &oauth2.Config{}

return oAuthConfig.Client(oauth2.NoContext, token), nil
}

// func NewClientAccessToken(accessToken string) *http.Client {
func NewClientBearerTokenSimple(accessToken string) *http.Client {
token := &oauth2.Token{
Expand Down
5 changes: 3 additions & 2 deletions ringcentral/examples/get_account/get_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ func main() {
ClientSecret: os.Getenv("RINGCENTRAL_CLIENT_SECRET"),
ServerURL: os.Getenv("RINGCENTRAL_SERVER_URL")},
ringcentral.PasswordCredentials{
Username: os.Getenv("RINGCENTRAL_USERNAME"),
Password: os.Getenv("RINGCENTRAL_PASSWORD")})
Username: os.Getenv("RINGCENTRAL_USERNAME"),
Extension: os.Getenv("RINGCENTRAL_EXTENSION"),
Password: os.Getenv("RINGCENTRAL_PASSWORD")})
}
if err != nil {
panic(err)
Expand Down

0 comments on commit 5e5d9f5

Please sign in to comment.