-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sso session and token provider support (#4885)
Update sso credential provider logic to support both sso token provider and legacy sso config, which can all be resolved from updated shared config profile and sso session section.
- Loading branch information
1 parent
75e508d
commit d744468
Showing
22 changed files
with
1,255 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package bearer | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"time" | ||
) | ||
|
||
// Token provides a type wrapping a bearer token and expiration metadata. | ||
type Token struct { | ||
Value string | ||
|
||
CanExpire bool | ||
Expires time.Time | ||
} | ||
|
||
// Expired returns if the token's Expires time is before or equal to the time | ||
// provided. If CanExpire is false, Expired will always return false. | ||
func (t Token) Expired(now time.Time) bool { | ||
if !t.CanExpire { | ||
return false | ||
} | ||
now = now.Round(0) | ||
return now.Equal(t.Expires) || now.After(t.Expires) | ||
} | ||
|
||
// TokenProvider provides interface for retrieving bearer tokens. | ||
type TokenProvider interface { | ||
RetrieveBearerToken(aws.Context) (Token, error) | ||
} | ||
|
||
// TokenProviderFunc provides a helper utility to wrap a function as a type | ||
// that implements the TokenProvider interface. | ||
type TokenProviderFunc func(aws.Context) (Token, error) | ||
|
||
// RetrieveBearerToken calls the wrapped function, returning the Token or | ||
// error. | ||
func (fn TokenProviderFunc) RetrieveBearerToken(ctx aws.Context) (Token, error) { | ||
return fn(ctx) | ||
} | ||
|
||
// StaticTokenProvider provides a utility for wrapping a static bearer token | ||
// value within an implementation of a token provider. | ||
type StaticTokenProvider struct { | ||
Token Token | ||
} | ||
|
||
// RetrieveBearerToken returns the static token specified. | ||
func (s StaticTokenProvider) RetrieveBearerToken(aws.Context) (Token, error) { | ||
return s.Token, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.