Skip to content

Commit

Permalink
oauth2: Refactor JWT strategy
Browse files Browse the repository at this point in the history
Signed-off-by: Prateek Malhotra <[email protected]>
  • Loading branch information
someone1 committed Aug 3, 2018
1 parent 4ea7496 commit d39b573
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmd/server/handler_oauth2_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func newOAuth2Handler(c *config.Config, router *httprouter.Router, cm consent.Ma
L: c.GetLogger(),
OpenIDJWTStrategy: openIDJWTStrategy,
AccessTokenJWTStrategy: accessTokenJWTStrategy,
AccessTokenStrategy: c.OAuth2AccessTokenStrategy,
IDTokenLifespan: c.GetIDTokenLifespan(),
}

Expand Down
6 changes: 6 additions & 0 deletions jwk/jwt_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ import (
"github.com/pkg/errors"
)

type JWTStrategy interface {
GetPublicKeyID() (string, error)

jwt.JWTStrategy
}

func NewRS256JWTStrategy(m Manager, set string) (*RS256JWTStrategy, error) {
j := &RS256JWTStrategy{
Manager: m,
Expand Down
4 changes: 2 additions & 2 deletions oauth2/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func (h *Handler) TokenHandler(w http.ResponseWriter, r *http.Request, _ httprou

if accessRequest.GetGrantTypes().Exact("client_credentials") {
var accessTokenKeyID string
if h.AccessTokenJWTStrategy != nil {
if h.AccessTokenStrategy == "jwt" {
accessTokenKeyID, err = h.AccessTokenJWTStrategy.GetPublicKeyID()
if err != nil {
pkg.LogError(err, h.L)
Expand Down Expand Up @@ -557,7 +557,7 @@ func (h *Handler) AuthHandler(w http.ResponseWriter, r *http.Request, _ httprout
}

var accessTokenKeyID string
if h.AccessTokenJWTStrategy != nil {
if h.AccessTokenStrategy == "jwt" {
accessTokenKeyID, err = h.AccessTokenJWTStrategy.GetPublicKeyID()
if err != nil {
pkg.LogError(err, h.L)
Expand Down
5 changes: 3 additions & 2 deletions oauth2/handler_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ type Handler struct {
IDTokenLifespan time.Duration
CookieStore sessions.Store

OpenIDJWTStrategy *jwk.RS256JWTStrategy
AccessTokenJWTStrategy *jwk.RS256JWTStrategy
OpenIDJWTStrategy jwk.JWTStrategy
AccessTokenJWTStrategy jwk.JWTStrategy
AccessTokenStrategy string

L logrus.FieldLogger

Expand Down

0 comments on commit d39b573

Please sign in to comment.