forked from shaj13/go-guardian
/
options.go
46 lines (40 loc) · 1.12 KB
/
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
42
43
44
45
46
package token
import (
"crypto"
"github.com/Sosivio/go-guardian/v2/auth"
"github.com/Sosivio/go-guardian/v2/auth/internal"
)
// SetType sets the authentication token type or scheme,
// used for HTTP WWW-Authenticate header.
//
// Deprecated: No longer used.
func SetType(t Type) auth.Option {
return auth.OptionFunc(func(v interface{}) {
})
}
// SetParser sets the strategy token parser.
func SetParser(p Parser) auth.Option {
return auth.OptionFunc(func(v interface{}) {
if v, ok := v.(*core); ok {
v.parser = p
}
})
}
// SetScopes sets the scopes to be used when verifying user access token.
func SetScopes(scopes ...Scope) auth.Option {
return auth.OptionFunc(func(v interface{}) {
if v, ok := v.(*core); ok {
v.verify = verifyScopes(scopes...)
}
})
}
// SetHash apply token hashing based on HMAC with h and key,
// To prevent precomputation and length extension attacks,
// and to mitigates hash map DOS attacks via collisions.
func SetHash(h crypto.Hash, key []byte) auth.Option {
return auth.OptionFunc(func(v interface{}) {
if v, ok := v.(*core); ok {
v.hasher = internal.NewHMACHasher(h, key)
}
})
}