-
Notifications
You must be signed in to change notification settings - Fork 11
fix(api): Google OAuth provider #26
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
Open
kelkawi-a
wants to merge
7
commits into
tuannvm:main
Choose a base branch
from
kelkawi-a:fix/google-oauth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
470322b
fix(api): Google OAuth provider
kelkawi-a 3c1fb73
address review comments
kelkawi-a 99dac51
address review comments
kelkawi-a 1d17606
address review comments
kelkawi-a 1421767
fix regression
kelkawi-a 18c789b
address review comment
kelkawi-a 087f3b7
Merge branch 'main' into fix/google-oauth
kelkawi-a 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package oauth | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "golang.org/x/oauth2" | ||
| ) | ||
|
|
||
| func TestBuildTokenResponseGoogleOpaqueAccessTokenUsesIDToken(t *testing.T) { | ||
| handler := &OAuth2Handler{ | ||
| config: &OAuth2Config{Provider: "google"}, | ||
| logger: &defaultLogger{}, | ||
| } | ||
|
|
||
| idToken := "header.payload.signature" | ||
| token := (&oauth2.Token{ | ||
| AccessToken: "ya29.a0ARW5m7Opaque", | ||
| TokenType: "Bearer", | ||
| RefreshToken: "refresh-token", | ||
| Expiry: time.Now().Add(time.Hour), | ||
| }).WithExtra(map[string]interface{}{ | ||
| "id_token": idToken, | ||
| "scope": "openid profile email", | ||
| }) | ||
|
|
||
| response := handler.buildTokenResponse(token) | ||
|
|
||
| if response["access_token"] != idToken { | ||
| t.Fatalf("expected access_token to be mapped to id_token for Google opaque token") | ||
| } | ||
|
|
||
| if response["id_token"] != idToken { | ||
| t.Fatalf("expected id_token in response") | ||
| } | ||
|
|
||
| if response["refresh_token"] != "refresh-token" { | ||
| t.Fatalf("expected refresh_token in response") | ||
| } | ||
| } | ||
|
|
||
| func TestBuildTokenResponseGoogleJWTAccessTokenPreserved(t *testing.T) { | ||
| handler := &OAuth2Handler{ | ||
| config: &OAuth2Config{Provider: "google"}, | ||
| logger: &defaultLogger{}, | ||
| } | ||
|
|
||
| jwtAccessToken := "jwt.access.token" | ||
| token := (&oauth2.Token{ | ||
| AccessToken: jwtAccessToken, | ||
| TokenType: "Bearer", | ||
| Expiry: time.Now().Add(time.Hour), | ||
| }).WithExtra(map[string]interface{}{ | ||
| "id_token": "id.token.value", | ||
| }) | ||
|
|
||
| response := handler.buildTokenResponse(token) | ||
|
|
||
| if response["access_token"] != jwtAccessToken { | ||
| t.Fatalf("expected JWT access_token to remain unchanged") | ||
| } | ||
| } | ||
|
|
||
| func TestBuildTokenResponseNonGoogleAccessTokenPreserved(t *testing.T) { | ||
| handler := &OAuth2Handler{ | ||
| config: &OAuth2Config{Provider: "okta"}, | ||
| logger: &defaultLogger{}, | ||
| } | ||
|
|
||
| token := (&oauth2.Token{ | ||
| AccessToken: "opaque-token-value", | ||
| TokenType: "Bearer", | ||
| Expiry: time.Now().Add(time.Hour), | ||
| }).WithExtra(map[string]interface{}{ | ||
| "id_token": "id.token.value", | ||
| }) | ||
|
|
||
| response := handler.buildTokenResponse(token) | ||
|
|
||
| if response["access_token"] != "opaque-token-value" { | ||
| t.Fatalf("expected non-Google access_token to remain unchanged") | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.