Add support for resource indicator to OIDC provider (#131)

This commit is contained in:
Thom Seddon
2020-06-11 12:24:51 +01:00
committed by GitHub
parent fb8b216481
commit 2937b04fdb
4 changed files with 37 additions and 2 deletions

View File

@ -36,6 +36,8 @@ type User struct {
// OAuthProvider is a provider using the oauth2 library
type OAuthProvider struct {
Resource string `long:"resource" env:"RESOURCE" description:"Optional resource indicator"`
Config *oauth2.Config
ctx context.Context
}
@ -51,6 +53,11 @@ func (p *OAuthProvider) ConfigCopy(redirectURI string) oauth2.Config {
// OAuthGetLoginURL provides a base "GetLoginURL" for proiders using OAauth2
func (p *OAuthProvider) OAuthGetLoginURL(redirectURI, state string) string {
config := p.ConfigCopy(redirectURI)
if p.Resource != "" {
return config.AuthCodeURL(state, oauth2.SetAuthURLParam("resource", p.Resource))
}
return config.AuthCodeURL(state)
}