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

feat: Add scopes option to client #1082

Merged
merged 7 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions oidc_cli/oidc_impl/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// Client is an oauth client
type Client struct {
provider *oidc.Provider
oauthConfig *oauth2.Config
OauthConfig *oauth2.Config
verifier *oidc.IDTokenVerifier
server *server

Expand Down Expand Up @@ -68,7 +68,7 @@ func NewClient(ctx context.Context, config *Config, clientOptions ...Option) (*C
clientConfig := &Client{
provider: provider,
verifier: verifier,
oauthConfig: oauthConfig,
OauthConfig: oauthConfig,

server: server,
customMessages: map[oidcStatus]string{
Expand Down Expand Up @@ -110,7 +110,7 @@ func (c *Client) idTokenFromOauth2Token(

// RefreshToken will fetch a new token
func (c *Client) RefreshToken(ctx context.Context, oldToken *Token) (*Token, error) {
logrus.Debugf("refresh scopes: %#v", c.oauthConfig.Scopes)
logrus.Debugf("refresh scopes: %#v", c.OauthConfig.Scopes)

newToken, err := c.refreshToken(ctx, oldToken)
// if we could refresh successfully, do so.
Expand All @@ -135,7 +135,7 @@ func (c *Client) refreshToken(ctx context.Context, token *Token) (*Token, error)
Expiry: token.Expiry,
}

tokenSource := c.oauthConfig.TokenSource(ctx, oauthToken)
tokenSource := c.OauthConfig.TokenSource(ctx, oauthToken)

newOauth2Token, err := tokenSource.Token()
if err != nil {
Expand Down Expand Up @@ -168,7 +168,7 @@ func (c *Client) refreshToken(ctx context.Context, token *Token) (*Token, error)

// GetAuthCodeURL gets the url to the oauth2 consent page
func (c *Client) GetAuthCodeURL(oauthMaterial *oauthMaterial) string {
return c.oauthConfig.AuthCodeURL(
return c.OauthConfig.AuthCodeURL(
oauthMaterial.State,
oauth2.SetAuthURLParam("grant_type", "refresh_token"),
oauth2.SetAuthURLParam("code_challenge", oauthMaterial.CodeChallenge),
Expand All @@ -187,12 +187,12 @@ func (c *Client) ValidateState(ourState []byte, otherState []byte) error {

// Exchange will exchange a token
func (c *Client) Exchange(ctx context.Context, code string, codeVerifier string) (*oauth2.Token, error) {
token, err := c.oauthConfig.Exchange(
token, err := c.OauthConfig.Exchange(
ctx,
code,
oauth2.SetAuthURLParam("grant_type", "authorization_code"),
oauth2.SetAuthURLParam("code_verifier", codeVerifier),
oauth2.SetAuthURLParam("client_id", c.oauthConfig.ClientID),
oauth2.SetAuthURLParam("client_id", c.OauthConfig.ClientID),
)
return token, errors.Wrap(err, "failed to exchange oauth token")
}
Expand Down
8 changes: 7 additions & 1 deletion oidc_cli/oidc_impl/client/config_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ var SetSuccessMessage = func(successMessage string) Option {

var SetOauth2AuthStyle = func(authStyle oauth2.AuthStyle) Option {
return func(c *Client) {
c.oauthConfig.Endpoint.AuthStyle = authStyle
c.OauthConfig.Endpoint.AuthStyle = authStyle
}
}

var SetScopeOptions = func(scopes []string) Option {
return func(c *Client) {
c.OauthConfig.Scopes = scopes
}
}
Loading