Skip to content

Commit

Permalink
openid: Improves validation errors and uses UTC everywhere (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
arekkas authored May 19, 2018
1 parent 7ccad77 commit eee3dad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions handler/openid/strategy_jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,16 @@ func (h DefaultStrategy) GenerateIDToken(_ context.Context, requester fosite.Req
}

if maxAge > 0 {
if claims.AuthTime.IsZero() || claims.AuthTime.After(time.Now()) {
if claims.AuthTime.IsZero() || claims.AuthTime.After(time.Now().UTC()) {
return "", errors.WithStack(fosite.ErrServerError.WithDebug("Failed to generate id token because authentication time claim is required when max_age is set and can not be in the future"))
} else if claims.AuthTime.Add(time.Second * time.Duration(maxAge)).Before(time.Now()) {
} else if claims.AuthTime.Add(time.Second * time.Duration(maxAge)).Before(time.Now().UTC()) {
return "", errors.WithStack(fosite.ErrServerError.WithDebug("Failed to generate id token because authentication time does not satisfy max_age time"))
}
}

prompt := requester.GetRequestForm().Get("prompt")
if prompt != "" {
if claims.AuthTime.IsZero() || claims.AuthTime.After(time.Now()) {
if claims.AuthTime.IsZero() || claims.AuthTime.After(time.Now().UTC()) {
return "", errors.WithStack(fosite.ErrServerError.WithDebug("Unable to determine validity of prompt parameter because auth_time is missing in id token claims"))
}
}
Expand Down
6 changes: 5 additions & 1 deletion handler/openid/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ func (v *OpenIDConnectRequestValidator) ValidatePrompt(req fosite.AuthorizeReque
return errors.WithStack(fosite.ErrServerError.WithDebug("Failed to validate OpenID Connect request because session subject is empty"))
}

if claims.AuthTime.After(time.Now().UTC()) {
return errors.WithStack(fosite.ErrServerError.WithDebug("Failed to validate OpenID Connect request because authentication time is in the future"))
}

if maxAge > 0 {
if claims.AuthTime.IsZero() || claims.AuthTime.After(time.Now()) {
if claims.AuthTime.IsZero() {
return errors.WithStack(fosite.ErrServerError.WithDebug("Failed to validate OpenID Connect request because authentication time claim is required when max_age is set and can not be in the future"))
} else if claims.AuthTime.Add(time.Second * time.Duration(maxAge)).Before(time.Now()) {
return errors.WithStack(fosite.ErrLoginRequired.WithDebug("Failed to validate OpenID Connect request because authentication time does not satisfy max_age time"))
Expand Down
8 changes: 4 additions & 4 deletions handler/openid/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func TestValidatePrompt(t *testing.T) {
Subject: "foo",
Claims: &jwt.IDTokenClaims{
Subject: "foo",
RequestedAt: time.Now().UTC(),
AuthTime: time.Now().UTC().Add(time.Second),
RequestedAt: time.Now().UTC().Add(-time.Second*5),
AuthTime: time.Now().UTC().Add(-time.Second),
},
},
},
Expand All @@ -157,8 +157,8 @@ func TestValidatePrompt(t *testing.T) {
Subject: "foo",
Claims: &jwt.IDTokenClaims{
Subject: "foo",
RequestedAt: time.Now().UTC(),
AuthTime: time.Now().UTC().Add(time.Second),
RequestedAt: time.Now().UTC().Add(-time.Second*5),
AuthTime: time.Now().UTC().Add(-time.Second),
},
},
},
Expand Down

0 comments on commit eee3dad

Please sign in to comment.