@@ -8,13 +8,16 @@ import (
8
8
"net/url"
9
9
"path"
10
10
"strings"
11
+ "time"
11
12
12
13
"github.com/dgrijalva/jwt-go/v4"
13
14
"github.com/google/go-querystring/query"
14
15
"github.com/hashicorp/go-cleanhttp"
15
16
)
16
17
17
18
const (
19
+ HTTPpHeaderAuthorization = "Authorization"
20
+
18
21
// grant type values
19
22
GrantTypeCode = "code"
20
23
GrantTypeUMA2Ticket = "urn:ietf:params:oauth:grant-type:uma-ticket"
@@ -27,6 +30,25 @@ const (
27
30
UMA2ResponseModeDecision = "decision"
28
31
UMA2ResponseModePermissions = "permissions"
29
32
33
+ DecisionStrategyUnanimous = "UNANIMOUS"
34
+ DecisionStrategyAffirmative = "AFFIRMATIVE"
35
+ DecisionStrategyPositive = "POSITIVE"
36
+
37
+ PermissionTypeResource = "resource"
38
+ PermissionTypeRole = "role"
39
+
40
+ PolicyTypeRole = "role"
41
+ PolicyTypeJavascript = "js"
42
+ PolicyTypeTime = "time"
43
+
44
+ LogicPositive = "POSITIVE"
45
+ LogicNegative = "NEGATIVE"
46
+
47
+ // DefaultTokenExpirationMargin will be used if you do not specify your own ExpiryMargin key in the config
48
+ DefaultTokenExpirationMargin = 2 * time .Second
49
+ )
50
+
51
+ const (
30
52
// cache stuff
31
53
pkKeyPrefix = "pk"
32
54
pkKeyFormat = pkKeyPrefix + "\n %s\n %s\n %s"
@@ -38,7 +60,6 @@ const (
38
60
httpHeaderContentType = "Content-Type"
39
61
httpHeaderValueJSON = "application/json"
40
62
httpHeaderValueFormURLEncoded = "application/x-www-form-urlencoded"
41
- HTTPpHeaderAuthorization = "Authorization"
42
63
httpHeaderAuthorizationBearerPrefix = "Bearer"
43
64
httpHeaderAuthorizationBasicPrefix = "Basic"
44
65
httpHeaderAuthValueFormat = "%s %s"
@@ -91,6 +112,18 @@ const (
91
112
kcPathPartUsers = "users"
92
113
)
93
114
115
+ var ErrTokenExpired = errors .New ("token has expired" )
116
+
117
+ func IsTokenExpiredErr (err error ) bool {
118
+ for err != nil {
119
+ if errors .Is (err , ErrTokenExpired ) {
120
+ return true
121
+ }
122
+ err = errors .Unwrap (err )
123
+ }
124
+ return false
125
+ }
126
+
94
127
// DebugConfig
95
128
//
96
129
// This type contains configuration options that provide additional utility during testing or development, but should
@@ -211,7 +244,7 @@ func (c *APIClient) Do(ctx context.Context, req *APIRequest, mutators ...APIRequ
211
244
}
212
245
213
246
// Call is a helper method that wraps the creation of an *APIRequest type and executes it.
214
- func (c * APIClient ) Call (ctx context.Context , ap AuthProvider , method , requestURL string , body interface {}, mutators ... APIRequestMutator ) (* http.Response , error ) {
247
+ func (c * APIClient ) Call (ctx context.Context , ap AuthenticationProvider , method , requestURL string , body interface {}, mutators ... APIRequestMutator ) (* http.Response , error ) {
215
248
var (
216
249
req * APIRequest
217
250
err error
@@ -227,7 +260,7 @@ func (c *APIClient) Call(ctx context.Context, ap AuthProvider, method, requestUR
227
260
am []APIRequestMutator
228
261
err error
229
262
)
230
- if am , err = ap .AuthMutators (ctx , c ); err != nil {
263
+ if am , err = ap .RequestMutators (ctx , c ); err != nil {
231
264
return nil , err
232
265
}
233
266
mutators = requestMutators (mutators , am ... )
@@ -408,7 +441,7 @@ func (c *APIClient) keyFunc(ctx context.Context) jwt.Keyfunc {
408
441
}
409
442
}
410
443
411
- func (c * APIClient ) openIDConnectToken (ctx context.Context , realmName string , ap AuthProvider , req * OpenIDConnectTokenRequest , mutators ... APIRequestMutator ) (interface {}, error ) {
444
+ func (c * APIClient ) openIDConnectToken (ctx context.Context , realmName string , ap AuthenticationProvider , req * OpenIDConnectTokenRequest , mutators ... APIRequestMutator ) (interface {}, error ) {
412
445
var (
413
446
body url.Values
414
447
resp * http.Response
@@ -458,18 +491,18 @@ func (c *APIClient) realmsURL(realmName string, bits ...string) string {
458
491
return fmt .Sprintf (kcURLPathRealmsFormat , c .authServerURL , realmName , path .Join (bits ... ))
459
492
}
460
493
461
- func (c * APIClient ) callRealms (ctx context.Context , realmName string , ap AuthProvider , method , requestPath string , body interface {}, mutators ... APIRequestMutator ) (* http.Response , error ) {
494
+ func (c * APIClient ) callRealms (ctx context.Context , realmName string , ap AuthenticationProvider , method , requestPath string , body interface {}, mutators ... APIRequestMutator ) (* http.Response , error ) {
462
495
return c .Call (ctx , ap , method , c .realmsURL (realmName , requestPath ), body , mutators ... )
463
496
}
464
497
465
498
// AdminAPIClient is a simple extension of the base APIClient, adding /admin api calls
466
499
type AdminAPIClient struct {
467
500
* APIClient
468
501
realmName string
469
- ap AuthProvider
502
+ ap AuthenticationProvider
470
503
}
471
504
472
- func NewAdminAPIClient (config * APIClientConfig , realmName string , ap AuthProvider , mutators ... ConfigMutator ) (* AdminAPIClient , error ) {
505
+ func NewAdminAPIClient (config * APIClientConfig , realmName string , ap AuthenticationProvider , mutators ... ConfigMutator ) (* AdminAPIClient , error ) {
473
506
var (
474
507
c * APIClient
475
508
err error
@@ -492,19 +525,19 @@ func NewAdminAPIClientWithProvider(cp CombinedProvider, realmName string, mutato
492
525
493
526
func NewAdminAPIClientWithInstallDocument (id * InstallDocument , realmName string , mutators ... ConfigMutator ) (* AdminAPIClient , error ) {
494
527
// todo: support ID's for things other than a confidential client
495
- ctp , err := NewConfidentialClientAuthProvider ( & ConfidentialClientAuthProviderConfig { InstallDocument : id } )
528
+ ctp , err := NewClientSecretAuthenticationProvider ( NewClientSecretConfigWithInstallDocument ( id ) )
496
529
if err != nil {
497
530
return nil , err
498
531
}
499
532
return NewAdminAPIClientWithProvider (ctp , realmName , mutators ... )
500
533
}
501
534
502
535
// AdminClient returns a new AdminAPIClient for the provided realm (does not have to be the same as the auth'd realm)
503
- func (c * APIClient ) AdminClient (realmName string , ap AuthProvider ) * AdminAPIClient {
536
+ func (c * APIClient ) AdminClient (realmName string , ap AuthenticationProvider ) * AdminAPIClient {
504
537
return & AdminAPIClient {APIClient : c , realmName : realmName , ap : ap }
505
538
}
506
539
507
- func (c * AdminAPIClient ) AuthProvider () AuthProvider {
540
+ func (c * AdminAPIClient ) AuthProvider () AuthenticationProvider {
508
541
return c .ap
509
542
}
510
543
0 commit comments