feat: add http interceptor function for auth and token endpoints

This commit is contained in:
Livio Amstutz 2020-02-06 11:12:00 +01:00
parent 7e2c22f99b
commit f0d17fd839
2 changed files with 26 additions and 5 deletions

View file

@ -41,6 +41,7 @@ type DefaultOP struct {
http *http.Server
decoder *schema.Decoder
encoder *schema.Encoder
interceptor HttpInterceptor
}
type Config struct {
@ -98,6 +99,13 @@ func WithCustomUserinfoEndpoint(endpoint Endpoint) DefaultOPOpts {
}
}
func WithHttpInterceptor(h HttpInterceptor) DefaultOPOpts {
return func(o *DefaultOP) error {
o.interceptor = h
return nil
}
}
func NewDefaultOP(ctx context.Context, config *Config, storage Storage, opOpts ...DefaultOPOpts) (OpenIDProvider, error) {
err := ValidateIssuer(config.Issuer)
if err != nil {
@ -123,7 +131,7 @@ func NewDefaultOP(ctx context.Context, config *Config, storage Storage, opOpts .
p.discoveryConfig = CreateDiscoveryConfig(p, p.signer)
router := CreateRouter(p)
router := CreateRouter(p, p.interceptor)
p.http = &http.Server{
Addr: ":" + config.Port,
Handler: router,