Skip to content

Commit

Permalink
Add optional params to PasswordCredentialsToken
Browse files Browse the repository at this point in the history
Allow clients to pass additional URL parameters as part of the
PasswordCredentialsToken grant.

Fixes golang#259
  • Loading branch information
Simon Inman committed Dec 11, 2017
1 parent 3ea2187 commit 90f0b78
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ func (c *Config) AuthCodeURL(state string, opts ...AuthCodeOption) string {
return buf.String()
}

// A PasswordCredentialOption is passed to Config.AuthCodeURL.
type PasswordCredentialOption interface {

This comment has been minimized.

Copy link
@tiziano88

tiziano88 Dec 11, 2017

I would just reuse the existing AuthCodeOption and then at some point rename it (though that might be a breaking change).

This comment has been minimized.

Copy link
@tiziano88

tiziano88 Dec 11, 2017

Also I think this could be applicable to the Exchange method too.

setValue(url.Values)
}

// SetPasswordCredentialParam builds a PasswordCredentialToken which passes
// key/value parameters to a provider's authorization endpoint.
func SetPasswordCredentialParam(key, value string) PasswordCredentialOption {
return setParam{key, value}
}

// PasswordCredentialsToken converts a resource owner username and password
// pair into a token.
//
Expand All @@ -156,13 +167,17 @@ func (c *Config) AuthCodeURL(state string, opts ...AuthCodeOption) string {
//
// The HTTP client to use is derived from the context.
// If nil, http.DefaultClient is used.
func (c *Config) PasswordCredentialsToken(ctx context.Context, username, password string) (*Token, error) {
return retrieveToken(ctx, c, url.Values{
func (c *Config) PasswordCredentialsToken(ctx context.Context, username, password string, opts ...PasswordCredentialOption) (*Token, error) {
v := url.Values{
"grant_type": {"password"},
"username": {username},
"password": {password},
"scope": internal.CondVal(strings.Join(c.Scopes, " ")),
})
}
for _, opt := range opts {
opt.setValue(v)
}
return retrieveToken(ctx, c, v)
}

// Exchange converts an authorization code into a token.
Expand Down

0 comments on commit 90f0b78

Please sign in to comment.