Skip to content

Commit 90f0b78

Browse files
author
Simon Inman
committed
Add optional params to PasswordCredentialsToken
Allow clients to pass additional URL parameters as part of the PasswordCredentialsToken grant. Fixes golang#259
1 parent 3ea2187 commit 90f0b78

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

oauth2.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ func (c *Config) AuthCodeURL(state string, opts ...AuthCodeOption) string {
145145
return buf.String()
146146
}
147147

148+
// A PasswordCredentialOption is passed to Config.AuthCodeURL.
149+
type PasswordCredentialOption interface {
150+
setValue(url.Values)
151+
}
152+
153+
// SetPasswordCredentialParam builds a PasswordCredentialToken which passes
154+
// key/value parameters to a provider's authorization endpoint.
155+
func SetPasswordCredentialParam(key, value string) PasswordCredentialOption {
156+
return setParam{key, value}
157+
}
158+
148159
// PasswordCredentialsToken converts a resource owner username and password
149160
// pair into a token.
150161
//
@@ -156,13 +167,17 @@ func (c *Config) AuthCodeURL(state string, opts ...AuthCodeOption) string {
156167
//
157168
// The HTTP client to use is derived from the context.
158169
// If nil, http.DefaultClient is used.
159-
func (c *Config) PasswordCredentialsToken(ctx context.Context, username, password string) (*Token, error) {
160-
return retrieveToken(ctx, c, url.Values{
170+
func (c *Config) PasswordCredentialsToken(ctx context.Context, username, password string, opts ...PasswordCredentialOption) (*Token, error) {
171+
v := url.Values{
161172
"grant_type": {"password"},
162173
"username": {username},
163174
"password": {password},
164175
"scope": internal.CondVal(strings.Join(c.Scopes, " ")),
165-
})
176+
}
177+
for _, opt := range opts {
178+
opt.setValue(v)
179+
}
180+
return retrieveToken(ctx, c, v)
166181
}
167182

168183
// Exchange converts an authorization code into a token.

0 commit comments

Comments
 (0)