BedrockTokenProvider
extends TokenProvider
in package
Token provider for Bedrock that sources bearer tokens from environment variables.
Table of Contents
Constants
- BEARER_AUTH = 'smithy.api#httpBearerAuth'
- ENV_PROFILE = 'AWS_PROFILE'
- TOKEN_ENV_KEY = 'bearer_token_bedrock'
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.
- createIfAvailable() : callable|null
- Create a Bedrock token provider if the service is 'bedrock' and a token is available.
- defaultProvider() : callable
- Create a default Bedrock token provider that checks for a bearer token in the AWS_BEARER_TOKEN_BEDROCK environment variable.
- env() : callable
- Token provider that creates a token from an environment variable.
- fromToken() : callable
- Create a token provider function from a static token.
- fromTokenValue() : callable
- Create a token provider from a raw token value string.
- 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
BEARER_AUTH
public
mixed
BEARER_AUTH
= 'smithy.api#httpBearerAuth'
ENV_PROFILE
public
mixed
ENV_PROFILE
= 'AWS_PROFILE'
TOKEN_ENV_KEY
public
string
TOKEN_ENV_KEY
= 'bearer_token_bedrock'
used to resolve the AWS_BEARER_TOKEN_BEDROCK env var
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
callablechain()
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
callablecreateIfAvailable()
Create a Bedrock token provider if the service is 'bedrock' and a token is available.
public
static createIfAvailable(array<string|int, mixed> &$args) : callable|null
Sets auth scheme preference to bearer
auth.
Parameters
- $args : array<string|int, mixed>
-
Configuration arguments containing 'config' array
Return values
callable|null —Returns a token provider if conditions are met, null otherwise
defaultProvider()
Create a default Bedrock token provider that checks for a bearer token in the AWS_BEARER_TOKEN_BEDROCK environment variable.
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
callableenv()
Token provider that creates a token from an environment variable.
public
static env(string $configKey) : callable
Parameters
- $configKey : string
-
The configuration key that will be transformed to an environment variable name by ConfigurationResolver
Return values
callablefromToken()
Create a token provider function from a static token.
public
static fromToken(TokenInterface $token) : callable
Parameters
- $token : TokenInterface
Return values
callablefromTokenValue()
Create a token provider from a raw token value string.
public
static fromTokenValue(string $tokenValue) : callable
Bedrock bearer tokens sourced from env do not have an expiration
Parameters
- $tokenValue : string
-
The bearer token value
Return values
callablememoize()
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
callablesso()
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