-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
41 lines (33 loc) · 981 Bytes
/
options.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
package pkce
// Option enables variadic PKCE Key options to be configured.
type Option func(*Key) error
// WithChallengeMethod enables specifying the challenge transformation method.
// Should only be used to downgrade to plain if required.
func WithChallengeMethod(method Method) Option {
return func(key *Key) (err error) {
switch method {
case Plain, S256:
key.challengeMethod = method
default:
return ErrMethodNotSupported
}
return nil
}
}
// WithCodeVerifier enables supplying your own code verifier. Disables code
// verifier generation.
func WithCodeVerifier(codeVerifier []byte) Option {
return func(key *Key) (err error) {
// validate incoming code verifier
err = key.setCodeVerifier(codeVerifier)
return
}
}
// WithCodeVerifierLength enables specifying the length of the code verifier
// to be generated.
func WithCodeVerifierLength(n int) Option {
return func(key *Key) (err error) {
err = key.setCodeVerifierLength(n)
return
}
}