-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjwk.go
52 lines (42 loc) · 1.09 KB
/
jwk.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package auth
import (
"fmt"
"github.com/MicahParks/keyfunc/v2"
"github.com/worldline-go/auth/models"
)
type ProviderExtra struct {
InfProvider
noop bool
}
func (p *ProviderExtra) IsNoop() bool {
return p.noop
}
// JWTKeyFunc returns a jwt.Keyfunc.
//
// Need GetCertURL in provider.
//
// If introspect is true, the introspect endpoint is used to verify the token.
// Use Parser function for introspect, not keyfunc.
func (p *ProviderExtra) JWTKeyFunc(opts ...OptionJWK) (models.InfKeyFuncParser, error) {
option := GetOptionJWK(opts...)
if option.Introspect {
return &IntrospectJWTKey{
URL: p.GetIntrospectURL(),
ClientID: p.GetClientID(),
ClientSecret: p.GetClientSecret(),
Ctx: option.Ctx,
}, nil
}
certURL := p.GetCertURL()
if certURL == "" {
return nil, fmt.Errorf("no cert URL")
}
keyOpts := MapOptionKeyfunc(option)
jwksKeyFunc, err := keyfunc.Get(certURL, keyOpts)
if err != nil {
return nil, fmt.Errorf("failed to get the JWKs from the given URL: %s; %w", certURL, err)
}
return &JwkKeyFuncParse{
KeyFunc: jwksKeyFunc.Keyfunc,
}, nil
}