New returns a new token provider
(cfg *config.Config, deps *Dependencies)
| 71 | |
| 72 | // New returns a new token provider |
| 73 | func New(cfg *config.Config, deps *Dependencies) (Provider, error) { |
| 74 | if cfg.JWTType == "" { |
| 75 | deps.Log.Debug().Msg("missing jwt type") |
| 76 | return nil, fmt.Errorf("missing jwt type") |
| 77 | } |
| 78 | signingMethod := jwt.GetSigningMethod(cfg.JWTType) |
| 79 | switch signingMethod { |
| 80 | case jwt.SigningMethodHS256, jwt.SigningMethodHS384, jwt.SigningMethodHS512: |
| 81 | if cfg.JWTSecret == "" { |
| 82 | deps.Log.Debug().Msg("missing jwt secret") |
| 83 | return nil, fmt.Errorf("missing jwt secret") |
| 84 | } |
| 85 | case jwt.SigningMethodRS256, jwt.SigningMethodRS384, jwt.SigningMethodRS512, |
| 86 | jwt.SigningMethodES256, jwt.SigningMethodES384, jwt.SigningMethodES512: |
| 87 | if cfg.JWTPrivateKey == "" { |
| 88 | deps.Log.Debug().Msg("missing jwt private key") |
| 89 | return nil, fmt.Errorf("missing jwt private key") |
| 90 | } |
| 91 | if cfg.JWTPublicKey == "" { |
| 92 | deps.Log.Debug().Msg("missing jwt public key") |
| 93 | return nil, fmt.Errorf("missing jwt public key") |
| 94 | } |
| 95 | } |
| 96 | return &provider{ |
| 97 | config: cfg, |
| 98 | dependencies: deps, |
| 99 | }, nil |
| 100 | } |
no outgoing calls