Class TokenProvider
- Aws\Token\TokenProvider uses Aws\Token\ParsesIniTrait
- Namespace: Aws\Token
- Located at Token/TokenProvider.php
Token providers are functions that accept no arguments and return a
promise that is fulfilled with an Aws\Token\TokenInterface
or rejected with an Aws\Exception\TokenException
.
use Aws\Token\TokenProvider; $provider = TokenProvider::defaultProvider(); // Returns a TokenInterface or throws. $token = $provider()->wait();
Token providers can be composed to create a token using conditional logic that can create different tokens in different environments. You can compose multiple providers into a single provider using Aws\Token\TokenProvider::chain. This function accepts providers as variadic arguments and returns a new function that will invoke each provider until a token is successfully returned.
Methods Summary
-
static
defaultProvider ( array $config = [] )
Create a default token provider tha checks for cached a SSO token from the CLI
-
static
fromToken ( Aws\Token\TokenInterface $token )
Create a token provider function from a static token.
-
static
chain ( )
Creates an aggregate token provider that invokes the provided variadic providers one after the other until a provider returns a token.
-
static
memoize ( callable $provider )
Wraps a token provider and caches a previously provided token. Ensures that cached tokens are refreshed when they expire.
-
static
cache ( callable $provider, Aws\CacheInterface $cache, string|null $cacheKey = null )
Wraps a token provider and saves provided token in an instance of Aws\CacheInterface. Forwards calls when no token found in cache and updates cache with the results.
-
static
sso ( string $profileName, string $filename, array $config = [] )
Token provider that creates a token from cached sso credentials
Methods Details
static callable defaultProvider ( array $config = [] )
Create a default token provider tha checks for cached a SSO token from the CLI
This provider is automatically wrapped in a memoize function that caches previously provided tokens.
Parameters
array | $config = [] | Optional array of token provider options. |
Returns
callable |
static
callable
fromToken (
Aws\Token\TokenInterface
$token
)
Create a token provider function from a static token.
Parameters
Aws\Token\TokenInterface |
$token |
Returns
callable |
static callable chain ( )
Creates an aggregate token provider that invokes the provided variadic providers one after the other until a provider returns a token.
Returns
callable |
static callable memoize ( callable $provider )
Wraps a token provider and caches a previously provided token. Ensures that cached tokens are refreshed when they expire.
Parameters
callable | $provider | Token provider function to wrap. |
Returns
callable |
static
callable
cache (
callable
$provider,
Aws\CacheInterface
$cache,
string|null
$cacheKey = null
)
Wraps a token provider and saves provided token in an instance of Aws\CacheInterface. Forwards calls when no token found in cache and updates cache with the results.
Parameters
callable | $provider | Token provider function to wrap |
Aws\CacheInterface |
$cache | Cache to store the token |
string|null | $cacheKey = null | (optional) Cache key to use |
Returns
callable |
static
Aws\Token\SsoToken
sso (
string
$profileName,
string
$filename,
array
$config = []
)
Token provider that creates a token from cached sso credentials
Parameters
string | $profileName | $ssoProfileName the name of the ini profile name |
string | $filename | the location of the ini file |
array | $config = [] | configuration options |
Returns
Aws\Token\SsoToken |
See
Constants summary
string |
ENV_PROFILE
|
#
'AWS_PROFILE'
|