/
options.go
64 lines (55 loc) · 1.73 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package userinfo
import (
"crypto/tls"
"net/http"
"github.com/shaj13/go-guardian/v2/auth"
"github.com/shaj13/go-guardian/v2/auth/claims"
"github.com/shaj13/go-guardian/v2/auth/internal"
"github.com/shaj13/go-guardian/v2/auth/strategies/oauth2"
)
// SetHTTPMethod sets http request's method.
// Default Get.
func SetHTTPMethod(method string) auth.Option {
return internal.SetRequesterMethod(method)
}
// SetHTTPClient sets underlying http client.
func SetHTTPClient(c *http.Client) auth.Option {
return internal.SetRequesterHTTPClient(c)
}
// SetTLSConfig sets underlying http client tls.
func SetTLSConfig(tls *tls.Config) auth.Option {
return internal.SetRequesterTLSConfig(tls)
}
// SetClientTransport sets underlying http client transport.
func SetClientTransport(rt http.RoundTripper) auth.Option {
return internal.SetRequesterClientTransport(rt)
}
// SetClaimResolver sets the introspection strategy ClaimResolver to resolve
// the authorization claim response.
// Default: introspection.Claim
func SetClaimResolver(c oauth2.ClaimsResolver) auth.Option {
return auth.OptionFunc(func(v interface{}) {
if k, ok := v.(*userinfo); ok {
k.claimResolver = c
}
})
}
// SetErrorResolver sets the introspection strategy ErrorResolver to resolve
// the authorization error response.
// Default: oauth2.ResponseError
func SetErrorResolver(e oauth2.ErrorResolver) auth.Option {
return auth.OptionFunc(func(v interface{}) {
if k, ok := v.(*userinfo); ok {
k.errorResolver = e
}
})
}
// SetVerifyOptions sets the introspection strategy to
// verify authorization response.
func SetVerifyOptions(opts claims.VerifyOptions) auth.Option {
return auth.OptionFunc(func(v interface{}) {
if k, ok := v.(*userinfo); ok {
k.opts = opts
}
})
}