-
Notifications
You must be signed in to change notification settings - Fork 3
feat(auth): Inject auth claims into request context and authenticate audience #540
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c6aae0f
feat(auth): Inject auth claims into request context
laouji 0550777
feat(auth): Add audience verification as additional check
laouji 30f0b65
Split between Stack middleware and Control Plane middleware to separa…
laouji 8169c45
Add AnnotatedModule function
laouji 2802870
Use exact string match for audience check
laouji 84c6e11
Add debug log for new auth middleware
laouji 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 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,68 @@ | ||
| package auth_test | ||
|
|
||
| import ( | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "github.com/formancehq/go-libs/v3/auth" | ||
| "github.com/formancehq/go-libs/v3/oidc" | ||
| ) | ||
|
|
||
| func TestCheckAudienceClaim(t *testing.T) { | ||
| tests := map[string]struct { | ||
| expectedAudienceStr string | ||
| claims *oidc.AccessTokenClaims | ||
| expectedError error | ||
| }{ | ||
| "NilClaims": { | ||
| claims: nil, | ||
| expectedError: errors.New("claims cannot be nil"), | ||
| }, | ||
| "MatchingAudience with url scheme": { | ||
| expectedAudienceStr: "http://example.com", | ||
| claims: &oidc.AccessTokenClaims{ | ||
| TokenClaims: oidc.TokenClaims{ | ||
| Audience: []string{"http://example.com"}, | ||
| }, | ||
| }, | ||
| expectedError: nil, | ||
| }, | ||
| "NonMatchingAudience with url scheme": { | ||
| expectedAudienceStr: "http://example.com", | ||
| claims: &oidc.AccessTokenClaims{ | ||
| TokenClaims: oidc.TokenClaims{ | ||
| Audience: []string{"http://another.com"}, | ||
| }, | ||
| }, | ||
| expectedError: oidc.ErrAudience, | ||
| }, | ||
| "Multiple audiences in claim; one matches": { | ||
| expectedAudienceStr: "example.com", | ||
| claims: &oidc.AccessTokenClaims{ | ||
| TokenClaims: oidc.TokenClaims{ | ||
| Audience: []string{"otherdomain.com", "example.com", "123.com"}, | ||
| }, | ||
| }, | ||
| expectedError: nil, | ||
| }, | ||
| "Multiple audiences in claim but none match": { | ||
| expectedAudienceStr: "http://example.com", | ||
| claims: &oidc.AccessTokenClaims{ | ||
| TokenClaims: oidc.TokenClaims{ | ||
| Audience: []string{"another.com", "ple.com", "subdomain.example.com"}, | ||
| }, | ||
| }, | ||
| expectedError: oidc.ErrAudience, | ||
| }, | ||
| } | ||
|
|
||
| for name, tt := range tests { | ||
| t.Run(name, func(t *testing.T) { | ||
| check := auth.CheckAudienceClaim(tt.expectedAudienceStr) | ||
| err := check(nil, tt.claims) | ||
| assert.Equal(t, tt.expectedError, err) | ||
| }) | ||
| } | ||
| } |
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,9 @@ | ||
| package auth | ||
|
|
||
| import "net/http" | ||
|
|
||
| //go:generate mockgen -source authenticator.go -destination authenticator_generated.go -package auth . Authenticator | ||
| type Authenticator interface { | ||
| Authenticate(w http.ResponseWriter, r *http.Request) (bool, error) | ||
| AuthenticateOnControlPlane(r *http.Request) (ControlPlaneAgent, error) | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.