@@ -5,25 +5,23 @@ import (
55 "net/http"
66
77 jwt "github.com/dgrijalva/jwt-go"
8- "github.com/netlify/git-gateway/conf"
98 "github.com/sirupsen/logrus"
109 "github.com/okta/okta-jwt-verifier-golang"
1110)
1211
1312type Authenticator interface {
14- // authenticate checks incoming requests for tokens presented using the Authorization header
13+ // ` authenticate` checks incoming requests for tokens presented using the Authorization header
1514 authenticate (w http.ResponseWriter , r * http.Request ) (context.Context , error )
1615 getName () string
1716}
1817
1918type Authorizer interface {
20- // authorize checks incoming requests for roles data in tokens that is parsed and verified by prior authentication step
19+ // ` authorize` checks incoming requests for roles data in tokens that is parsed and verified by a prior `authenticate` step
2120 authorize (w http.ResponseWriter , r * http.Request ) (context.Context , error )
2221 getName () string
2322}
2423
2524type Auth struct {
26- config * conf.GlobalConfiguration
2725 authenticator Authenticator
2826 authorizer Authorizer
2927 version string
@@ -44,10 +42,23 @@ type RolesAuthorizer struct {
4442 auth Auth
4543}
4644
47- func NewAuthWithVersion (ctx context.Context , globalConfig * conf.GlobalConfiguration , version string ) * Auth {
48- auth := & Auth {config : globalConfig , version : version }
45+ func NewAuthWithVersion (ctx context.Context , version string ) * Auth {
46+ config := getConfig (ctx )
47+ auth := & Auth {version : version }
48+ authenticatorName := config .JWT .Authenticator
49+
50+ if (authenticatorName == "bearer-jwt-token" ) {
51+ auth .authenticator = & JWTAuthenticator {name : "bearer-jwt-token" , auth : * auth }
52+ } else if (authenticatorName == "bearer-okta-jwt-token" ) {
53+ auth .authenticator = & OktaJWTAuthenticator {name : "bearer-okta-jwt-token" , auth : * auth }
54+ } else {
55+ if (authenticatorName != "" ) {
56+ logrus .Fatal ("Authenticator `%v` is not recognized" , authenticatorName )
57+ } else {
58+ logrus .Fatal ("Authenticator is not defined" )
59+ }
60+ }
4961
50- auth .authenticator = & OktaJWTAuthenticator {name : "bearer-jwt-token" , auth : * auth }
5162 auth .authorizer = & RolesAuthorizer {name : "bearer-jwt-token-roles" , auth : * auth }
5263
5364 return auth
0 commit comments