Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add client_credentials token method #431

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,24 @@ func (c *Config) PasswordCredentialsToken(ctx context.Context, username, passwor
return retrieveToken(ctx, c, v)
}

// The Client Credentials grant type is used by clients to obtain an access
// token outside of the context of a user.
//
// This is typically used by clients to access resources about themselves
// rather than to access a user's resources.
// See https://tools.ietf.org/html/rfc6749#section-4.4 for more info.
func (c *Config) ClientCredentialTokens(ctx context.Context) (*Token, error) {
v := url.Values{
"grant_type": {"client_credentials"},
"client_id": {c.ClientID},
"client_secret": {c.ClientSecret},
}
if len(c.Scopes) > 0 {
v.Set("scope", strings.Join(c.Scopes, " "))
}
return retrieveToken(ctx, c, v)
}

// Exchange converts an authorization code into a token.
//
// It is used after a resource provider redirects the user back
Expand Down