SDK for PHP 3.x

TokenProvider
in package
Uses ParsesIniTrait

Token providers are functions that accept no arguments and return a promise that is fulfilled with an {@see \Aws\Token\TokenInterface} or rejected with an {@see \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 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.

Table of Contents

Constants

ENV_PROFILE  = 'AWS_PROFILE'

Methods

cache()  : callable
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.
chain()  : callable
Creates an aggregate token provider that invokes the provided variadic providers one after the other until a provider returns a token.
defaultProvider()  : callable
Create a default token provider tha checks for cached a SSO token from the CLI
fromToken()  : callable
Create a token provider function from a static token.
memoize()  : callable
Wraps a token provider and caches a previously provided token.
sso()  : SsoTokenProvider
Token provider that creates a token from cached sso credentials

Constants

ENV_PROFILE

public mixed ENV_PROFILE = 'AWS_PROFILE'

Methods

cache()

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.

public static cache(callable $provider, CacheInterface $cache[, string|null $cacheKey = null ]) : callable
Parameters
$provider : callable

Token provider function to wrap

$cache : CacheInterface

Cache to store the token

$cacheKey : string|null = null

(optional) Cache key to use

Return values
callable

chain()

Creates an aggregate token provider that invokes the provided variadic providers one after the other until a provider returns a token.

public static chain() : callable
Return values
callable

defaultProvider()

Create a default token provider tha checks for cached a SSO token from the CLI

public static defaultProvider([array<string|int, mixed> $config = [] ]) : callable

This provider is automatically wrapped in a memoize function that caches previously provided tokens.

Parameters
$config : array<string|int, mixed> = []

Optional array of token provider options.

Return values
callable

fromToken()

Create a token provider function from a static token.

public static fromToken(TokenInterface $token) : callable
Parameters
$token : TokenInterface
Return values
callable

memoize()

Wraps a token provider and caches a previously provided token.

public static memoize(callable $provider) : callable

Ensures that cached tokens are refreshed when they expire.

Parameters
$provider : callable

Token provider function to wrap.

Return values
callable

sso()

Token provider that creates a token from cached sso credentials

public static sso(string $profileName, string $filename[, array<string|int, mixed> $config = [] ]) : SsoTokenProvider
Parameters
$profileName : string

the name of the ini profile name

$filename : string

the location of the ini file

$config : array<string|int, mixed> = []

configuration options

Tags
see
SsoTokenProvider

for $config details.

Return values
SsoTokenProvider
On this page