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
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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
__init__(region)
¶
Initialize the identity client with the specified region.
Source code in bedrock_agentcore/services/identity.py
75 76 77 78 79 80 81 82 83 84 85 86 87 | |
complete_resource_token_auth(session_uri, user_identifier)
¶
Confirms the user authentication session for obtaining OAuth2.0 tokens for a resource.
Source code in bedrock_agentcore/services/identity.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
create_api_key_credential_provider(req)
¶
Create an API key credential provider.
Source code in bedrock_agentcore/services/identity.py
94 95 96 97 | |
create_oauth2_credential_provider(req)
¶
Create an OAuth2 credential provider.
Source code in bedrock_agentcore/services/identity.py
89 90 91 92 | |
create_workload_identity(name=None, allowed_resource_oauth_2_return_urls=None)
¶
Create workload identity with optional name.
Source code in bedrock_agentcore/services/identity.py
118 119 120 121 122 123 124 125 126 127 | |
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
241 242 243 244 245 246 | |
get_token(*, provider_name, scopes=None, agent_identity_token, on_auth_url=None, auth_flow, callback_url=None, force_authentication=False, token_poller=None, custom_state=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
|
custom_state
|
Optional[str]
|
A state that allows applications to verify the validity of callbacks to callback_url |
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
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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
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
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
get_workload_identity(name)
¶
Retrieves information about a workload identity.
Source code in bedrock_agentcore/services/identity.py
138 139 140 141 | |
update_workload_identity(name, allowed_resource_oauth_2_return_urls)
¶
Update an existing workload identity with allowed resource OAuth2 callback urls.
Source code in bedrock_agentcore/services/identity.py
129 130 131 132 133 134 135 136 | |
TokenPoller
¶
Bases: ABC
Abstract base class for token polling implementations.
Source code in bedrock_agentcore/services/identity.py
16 17 18 19 20 21 22 | |
poll_for_token()
abstractmethod
async
¶
Poll for a token and return it when available.
Source code in bedrock_agentcore/services/identity.py
19 20 21 22 | |
UserIdIdentifier
¶
Bases: BaseModel
The ID of the user for whom you have retrieved a workload access token for.
Source code in bedrock_agentcore/services/identity.py
66 67 68 69 | |
UserTokenIdentifier
¶
Bases: BaseModel
The OAuth2.0 token issued by the user's identity provider.
Source code in bedrock_agentcore/services/identity.py
60 61 62 63 | |
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, custom_state=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
|
custom_state
|
Optional[str]
|
A state that allows applications to verify the validity of callbacks to callback_url |
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 94 95 96 | |
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
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 | |