-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Verify main vs extra JWT bearers differently #596
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,10 +2,15 @@ package providers | |||||
|
||||||
import ( | ||||||
"context" | ||||||
"crypto/rand" | ||||||
"crypto/rsa" | ||||||
"net/url" | ||||||
"testing" | ||||||
"time" | ||||||
|
||||||
"github.com/coreos/go-oidc" | ||||||
"github.com/dgrijalva/jwt-go" | ||||||
|
||||||
"github.com/oauth2-proxy/oauth2-proxy/pkg/apis/sessions" | ||||||
"github.com/stretchr/testify/assert" | ||||||
) | ||||||
|
@@ -47,3 +52,39 @@ func TestAcrValuesConfigured(t *testing.T) { | |||||
result := p.GetLoginURL("https://my.test.app/oauth", "") | ||||||
assert.Contains(t, result, "acr_values=testValue") | ||||||
} | ||||||
|
||||||
func TestCreateSessionStateFromBearerToken(t *testing.T) { | ||||||
minimalIDToken := jwt.StandardClaims{ | ||||||
Audience: "asdf1234", | ||||||
ExpiresAt: time.Now().Add(time.Duration(5) * time.Minute).Unix(), | ||||||
Id: "id-some-id", | ||||||
IssuedAt: time.Now().Unix(), | ||||||
Issuer: "https://issuer.example.com", | ||||||
NotBefore: 0, | ||||||
Subject: "123456789", | ||||||
} | ||||||
// From oidc_test.go | ||||||
verifier := oidc.NewVerifier( | ||||||
"https://issuer.example.com", | ||||||
fakeKeySetStub{}, | ||||||
&oidc.Config{ClientID: "asdf1234"}, | ||||||
) | ||||||
|
||||||
key, err := rsa.GenerateKey(rand.Reader, 2048) | ||||||
assert.NoError(t, err) | ||||||
rawIDToken, err := jwt.NewWithClaims(jwt.SigningMethodRS256, minimalIDToken).SignedString(key) | ||||||
assert.NoError(t, err) | ||||||
// Pass to a dummy Verifier to get an oidc.IDToken from the rawIDToken for our actual test below | ||||||
idToken, err := verifier.Verify(context.Background(), rawIDToken) | ||||||
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. There's got to be a cleaner way to get an 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. It is just a struct at the end of the day, you could theoretically construct it, but then you can't set the private methods. I think what you've done is probably the best we can do sadly |
||||||
assert.NoError(t, err) | ||||||
|
||||||
session, err := (*ProviderData)(nil).CreateSessionStateFromBearerToken(context.Background(), rawIDToken, idToken) | ||||||
assert.NoError(t, err) | ||||||
|
||||||
assert.Equal(t, rawIDToken, session.AccessToken) | ||||||
assert.Equal(t, rawIDToken, session.IDToken) | ||||||
assert.Equal(t, "123456789", session.Email) | ||||||
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. What is the overall architectural rationale for forcing a oauth2-proxy/providers/provider_default.go Line 155 in f7b28cb
I left the existing logic untouched -- but shouldn't oauth2-proxy/providers/provider_default.go Line 165 in f7b28cb
And should we allow 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. User ID claim was added so that we could make sure that a particular claim was added, to be considered the user, but the work hasn't been completed so it's only half way through As for falling back, I'm not sure why we are doing that, i think we currently require all sessions to have a user and email field that's not empty, so I guess that's why? I think I need to do some archaeology on this |
||||||
assert.Equal(t, "123456789", session.User) | ||||||
assert.Empty(t, session.RefreshToken) | ||||||
assert.Empty(t, session.PreferredUsername) | ||||||
} |
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.
I removed this and defaulted to the logging happening only if all verifiers failed. My users have been confused with error messages when 1st or 2nd verifiers on the array fail and the 3rd extraJwt Verifier succeeded (seeing the
failed
words even though it succeeded was confusing)