-
Notifications
You must be signed in to change notification settings - Fork 3
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!: customizable client scopes in oidc_impl package #1052
Closed
+37
−10
Closed
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
71c1473
wip: test a method of adding scopes
kuannie1 12cc78e
fix: try logging a bit more
kuannie1 ff65765
try just hardcoding one
kuannie1 0a8daef
add another debug statement for re-authenticating
kuannie1 6a811e6
try another delimiter
kuannie1 8a4e222
add another debug statement
kuannie1 c1e8bf1
try setting offline_access
kuannie1 8933f6a
try to include scopes
kuannie1 2329788
go back to +
kuannie1 0ce068b
fix: exclude email & groups for now
kuannie1 5f00c36
try adding some other scopes
kuannie1 8a6f8d4
empty initial scopes--add scopes if needed
kuannie1 2daaa57
unneeded debug statement
kuannie1 4f2e1ce
try original logic adding scopes
kuannie1 5fe29e8
Merge branch 'aku/set-scopes-if-needed' of github.com:chanzuckerberg/…
kuannie1 7d477e1
try this part again
kuannie1 0f78372
try this again
kuannie1 8f33632
add helper comment
kuannie1 f0722ed
don't need this
kuannie1 03f9ec1
don't need this
kuannie1 0dc6930
re-add space
kuannie1 03b9fee
re-add space
kuannie1 538dc94
Merge branch 'main' of github.com:chanzuckerberg/go-misc into aku/set…
kuannie1 19d1b5d
Merge branch 'main' of github.com:chanzuckerberg/go-misc into aku/set…
kuannie1 8ba7c51
small correction to debug statement
kuannie1 0354306
Merge branch 'main' into aku/set-scopes-if-needed
kuannie1 615e5d6
fix: add client secret
kuannie1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"fmt" | ||
"io" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"github.com/coreos/go-oidc" | ||
|
@@ -51,12 +52,7 @@ func NewClient(ctx context.Context, config *Config, clientOptions ...Option) (*C | |
ClientID: config.ClientID, | ||
RedirectURL: fmt.Sprintf("http://localhost:%d", server.GetBoundPort()), | ||
Endpoint: provider.Endpoint(), | ||
Scopes: []string{ | ||
oidc.ScopeOpenID, | ||
oidc.ScopeOfflineAccess, | ||
"email", | ||
"groups", | ||
}, | ||
Scopes: []string{}, // add through the AddScope clientOption | ||
} | ||
|
||
oidcConfig := &oidc.Config{ | ||
|
@@ -184,15 +180,31 @@ func (c *Client) ValidateState(ourState []byte, otherState []byte) error { | |
} | ||
return nil | ||
} | ||
func format_scopes(ctx context.Context, scopes []string) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency, let's user camelcase, and rename to |
||
// space-separated string: | ||
// https://www.oauth.com/oauth2-servers/server-side-apps/authorization-code/#:~:text=with%20the%20service.-,scope,(optional),-Include%20one%20or | ||
|
||
return strings.Join(scopes, "+") | ||
} | ||
|
||
// Exchange will exchange a token | ||
func (c *Client) Exchange(ctx context.Context, code string, codeVerifier string) (*oauth2.Token, error) { | ||
params := []oauth2.AuthCodeOption{oauth2.SetAuthURLParam("grant_type", "authorization_code"), | ||
oauth2.SetAuthURLParam("code_verifier", codeVerifier), | ||
oauth2.SetAuthURLParam("client_id", c.oauthConfig.ClientID), | ||
} | ||
|
||
if len(c.oauthConfig.Scopes) != 0 { | ||
scope_str := format_scopes(ctx, c.oauthConfig.Scopes) | ||
params = append(params, oauth2.SetAuthURLParam("scopes", scope_str)) | ||
logrus.Debugf("oauth scopes: %s", scope_str) | ||
} else { | ||
logrus.Debug("no scopes set") | ||
} | ||
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), | ||
params..., | ||
) | ||
return token, errors.Wrap(err, "failed to exchange oauth token") | ||
} | ||
|
@@ -221,7 +233,7 @@ func (c *Client) Authenticate(ctx context.Context) (*Token, error) { | |
if err != nil { | ||
return nil, err | ||
} | ||
|
||
logrus.Debugf("authenticate scopes: %+v", c.oauthConfig.Scopes) | ||
c.server.Start(ctx, c, oauthMaterial) | ||
fmt.Fprintf(os.Stderr, "Opening browser in order to authenticate with Okta, hold on a brief second...\n") | ||
time.Sleep(2 * time.Second) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will we always have to add all these scopes manually now? If so, would it be worth adding a function
AddDefaultScopes
that adds all of these?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hspitzley-czi That was my initial idea, but I'd understand if that's not ideal!
Do you mean adding a function like this to oidc_cli/oidc_impl/client/config_options.go?
Or like, adding all the default scopes if none are provided?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah like the
AddDefaultScopes
you defined here! Adding default scopes if none are provided would be nice too if possible, that way it's backwards compatible