| 1 |
package grants |
| 2 |
|
| 3 |
import "strings" |
| 4 |
|
| 5 |
type clientCredentialsGrantBasic struct { |
| 6 |
grantType string `schema:"grant_type"` |
| 7 |
scope string `schema:"scope"` |
| 8 |
} |
| 9 |
|
| 10 |
type clientCredentialsGrant struct { |
| 11 |
*clientCredentialsGrantBasic |
| 12 |
clientID string `schema:"client_id"` |
| 13 |
clientSecret string `schema:"client_secret"` |
| 14 |
} |
| 15 |
|
| 16 |
// ClientCredentialsGrantBasic creates an oauth2 `Client Credentials` Grant |
| 17 |
// sending client_id and client_secret as basic auth header |
| 18 |
func ClientCredentialsGrantBasic(scopes ...string) *clientCredentialsGrantBasic { |
| 19 |
return &clientCredentialsGrantBasic{ |
| 20 |
grantType: "client_credentials", |
| 21 |
scope: strings.Join(scopes, " "), |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
// ClientCredentialsGrantValues creates an oauth2 `Client Credentials` Grant |
| 26 |
// sending client_id and client_secret as form values |
| 27 |
func ClientCredentialsGrantValues(clientID, clientSecret string, scopes ...string) *clientCredentialsGrant { |
| 28 |
return &clientCredentialsGrant{ |
| 29 |
clientCredentialsGrantBasic: ClientCredentialsGrantBasic(scopes...), |
| 30 |
clientID: clientID, |
| 31 |
clientSecret: clientSecret, |
| 32 |
} |
| 33 |
} |