Skip to content

Commit

Permalink
resolve (most) review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
muhlemmer committed Mar 10, 2023
1 parent 434b3fa commit 5bf7208
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 19 deletions.
1 change: 0 additions & 1 deletion example/server/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@ func (s *Storage) setUserinfo(ctx context.Context, userInfo *oidc.UserInfo, user
case oidc.ScopeEmail:
userInfo.Email = user.Email
userInfo.EmailVerified = oidc.Bool(user.EmailVerified)
//user.Email, user.EmailVerified
case oidc.ScopeProfile:
userInfo.PreferredUsername = user.Username
userInfo.Name = user.FirstName + " " + user.LastName
Expand Down
7 changes: 3 additions & 4 deletions pkg/client/rp/verifier_tokens_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import (
)

// MyCustomClaims extends the TokenClaims base,
// so it implments the oidc.Claims interface.
// Instead of carying a map, we add needed fields
// to the struct for type safe access.
// so it implmeents the oidc.Claims interface.
// Instead of carrying a map, we add needed fields// to the struct for type safe access.
type MyCustomClaims struct {
oidc.TokenClaims
NotBefore oidc.Time `json:"nbf,omitempty"`
Expand All @@ -34,7 +33,7 @@ type Nested struct {
}

/*
idToken caries the following claims. foo and bar are custom claims
idToken carries the following claims. foo and bar are custom claims
{
"acr": "something",
Expand Down
48 changes: 38 additions & 10 deletions pkg/oidc/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,46 @@ type TokenClaims struct {
SignatureAlg jose.SignatureAlgorithm `json:"-"`
}

func (c *TokenClaims) GetIssuer() string { return c.Issuer }
func (c *TokenClaims) GetSubject() string { return c.Subject }
func (c *TokenClaims) GetAudience() []string { return c.Audience }
func (c *TokenClaims) GetExpiration() time.Time { return c.Expiration.AsTime() }
func (c *TokenClaims) GetIssuedAt() time.Time { return c.IssuedAt.AsTime() }
func (c *TokenClaims) GetNonce() string { return c.Nonce }
func (c *TokenClaims) GetAuthTime() time.Time { return c.AuthTime.AsTime() }
func (c *TokenClaims) GetAuthorizedParty() string { return c.AuthorizedParty }
func (c *TokenClaims) GetSignatureAlgorithm() jose.SignatureAlgorithm { return c.SignatureAlg }
func (c *TokenClaims) GetIssuer() string {
return c.Issuer
}

func (c *TokenClaims) GetSubject() string {
return c.Subject
}

func (c *TokenClaims) GetAudience() []string {
return c.Audience
}

func (c *TokenClaims) GetExpiration() time.Time {
return c.Expiration.AsTime()
}

func (c *TokenClaims) GetIssuedAt() time.Time {
return c.IssuedAt.AsTime()
}

func (c *TokenClaims) GetNonce() string {
return c.Nonce
}

func (c *TokenClaims) GetAuthTime() time.Time {
return c.AuthTime.AsTime()
}

func (c *TokenClaims) GetAuthorizedParty() string {
return c.AuthorizedParty
}

func (c *TokenClaims) GetSignatureAlgorithm() jose.SignatureAlgorithm {
return c.SignatureAlg
}

func (c *TokenClaims) GetAuthenticationContextClassReference() string {
return c.AuthenticationContextClassReference
}

func (c *TokenClaims) SetSignatureAlgorithm(algorithm jose.SignatureAlgorithm) {
c.SignatureAlg = algorithm
}
Expand Down Expand Up @@ -110,7 +138,7 @@ type IDTokenClaims struct {
NotBefore Time `json:"nbf,omitempty"`
AccessTokenHash string `json:"at_hash,omitempty"`
CodeHash string `json:"c_hash,omitempty"`
SessionID string `json:"sid,omitempty"` // IDToken - session management spec
SessionID string `json:"sid,omitempty"`
UserInfoProfile
UserInfoEmail
UserInfoPhone
Expand Down
13 changes: 13 additions & 0 deletions pkg/oidc/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ func TestNewAccessTokenClaims(t *testing.T) {
want.Expiration.AsTime(), want.JWTID, "foo", time.Second,
)

// test if the dynamic timestamps are around now,
// allowing for a delta of 1, just in case we flip on
// either side of a second boundry.
nowMinusSkew := NowTime() - 1
assert.InDelta(t, int64(nowMinusSkew), int64(got.IssuedAt), 1)
assert.InDelta(t, int64(nowMinusSkew), int64(got.NotBefore), 1)

// Make equal not fail on dynamic timestamp
got.IssuedAt = 0
got.NotBefore = 0
Expand Down Expand Up @@ -207,6 +214,12 @@ func TestNewIDTokenClaims(t *testing.T) {
time.Second,
)

// test if the dynamic timestamp is around now,
// allowing for a delta of 1, just in case we flip on
// either side of a second boundry.
nowMinusSkew := NowTime() - 1
assert.InDelta(t, int64(nowMinusSkew), int64(got.IssuedAt), 1)

// Make equal not fail on dynamic timestamp
got.IssuedAt = 0

Expand Down
7 changes: 3 additions & 4 deletions pkg/op/verifier_access_token_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import (
)

// MyCustomClaims extends the TokenClaims base,
// so it implments the oidc.Claims interface.
// Instead of carying a map, we add needed fields
// to the struct for type safe access.
// so it implements the oidc.Claims interface.
// Instead of carrying a map, we add needed fields// to the struct for type safe access.
type MyCustomClaims struct {
oidc.TokenClaims
NotBefore oidc.Time `json:"nbf,omitempty"`
Expand All @@ -31,7 +30,7 @@ type Nested struct {
}

/*
accessToken caries the following claims. foo and bar are custom claims
accessToken carries the following claims. foo and bar are custom claims
{
"aud": [
Expand Down

0 comments on commit 5bf7208

Please sign in to comment.