Identity¶
Memory management for Bedrock AgentCore SDK.
Service client¶
bedrock_agentcore.services.identity
¶
The main high-level client for the Bedrock AgentCore Identity service.
IdentityClient
¶
A high-level client for Bedrock AgentCore Identity.
Source code in bedrock_agentcore/services/identity.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|
__init__(region)
¶
Initialize the identity client with the specified region.
Source code in bedrock_agentcore/services/identity.py
62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
create_api_key_credential_provider(req)
¶
Create an API key credential provider.
Source code in bedrock_agentcore/services/identity.py
81 82 83 84 |
|
create_oauth2_credential_provider(req)
¶
Create an OAuth2 credential provider.
Source code in bedrock_agentcore/services/identity.py
76 77 78 79 |
|
create_workload_identity(name=None)
¶
Create workload identity with optional name.
Source code in bedrock_agentcore/services/identity.py
105 106 107 108 109 110 |
|
get_api_key(*, provider_name, agent_identity_token)
async
¶
Programmatically retrieves an API key from the Identity service.
Source code in bedrock_agentcore/services/identity.py
187 188 189 190 191 192 |
|
get_token(*, provider_name, scopes=None, agent_identity_token, on_auth_url=None, auth_flow, callback_url=None, force_authentication=False, token_poller=None)
async
¶
Get an OAuth2 access token for the specified provider.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider_name
|
str
|
The credential provider name |
required |
scopes
|
Optional[List[str]]
|
Optional list of OAuth2 scopes to request |
None
|
agent_identity_token
|
str
|
Agent identity token for authentication |
required |
on_auth_url
|
Optional[Callable[[str], Any]]
|
Callback for handling authorization URLs |
None
|
auth_flow
|
Literal['M2M', 'USER_FEDERATION']
|
Authentication flow type ("M2M" or "USER_FEDERATION") |
required |
callback_url
|
Optional[str]
|
OAuth2 callback URL (must be pre-registered) |
None
|
force_authentication
|
bool
|
Force re-authentication even if token exists in the token vault |
False
|
token_poller
|
Optional[TokenPoller]
|
Custom token poller implementation |
None
|
Returns:
Type | Description |
---|---|
str
|
The access token string |
Raises:
Type | Description |
---|---|
RequiresUserConsentException
|
When user consent is needed |
Source code in bedrock_agentcore/services/identity.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
get_workload_access_token(workload_name, user_token=None, user_id=None)
¶
Get a workload access token using workload name and optionally user token.
Source code in bedrock_agentcore/services/identity.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
TokenPoller
¶
Bases: ABC
Abstract base class for token polling implementations.
Source code in bedrock_agentcore/services/identity.py
15 16 17 18 19 20 21 |
|
poll_for_token()
abstractmethod
async
¶
Poll for a token and return it when available.
Source code in bedrock_agentcore/services/identity.py
18 19 20 21 |
|
Decorators¶
bedrock_agentcore.identity
¶
Bedrock AgentCore SDK identity package.
requires_access_token(*, provider_name, into='access_token', scopes, on_auth_url=None, auth_flow, callback_url=None, force_authentication=False, token_poller=None)
¶
Decorator that fetches an OAuth2 access token before calling the decorated function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider_name
|
str
|
The credential provider name |
required |
into
|
str
|
Parameter name to inject the token into |
'access_token'
|
scopes
|
List[str]
|
OAuth2 scopes to request |
required |
on_auth_url
|
Optional[Callable[[str], Any]]
|
Callback for handling authorization URLs |
None
|
auth_flow
|
Literal['M2M', 'USER_FEDERATION']
|
Authentication flow type ("M2M" or "USER_FEDERATION") |
required |
callback_url
|
Optional[str]
|
OAuth2 callback URL |
None
|
force_authentication
|
bool
|
Force re-authentication |
False
|
token_poller
|
Optional[TokenPoller]
|
Custom token poller implementation |
None
|
Returns:
Type | Description |
---|---|
Callable
|
Decorator function |
Source code in bedrock_agentcore/identity/auth.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
requires_api_key(*, provider_name, into='api_key')
¶
Decorator that fetches an API key before calling the decorated function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider_name
|
str
|
The credential provider name |
required |
into
|
str
|
Parameter name to inject the API key into |
'api_key'
|
Returns:
Type | Description |
---|---|
Callable
|
Decorator function |
Source code in bedrock_agentcore/identity/auth.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|