create_token
async
¶
create_token(
client_id: ClientId,
client_secret: ClientSecret,
grant_type: GrantType,
*,
config_overrides: Optional[AsyncSSOOIDCClientConfig] = None,
device_code: Optional[DeviceCode] = None,
code: Optional[AuthCode] = None,
refresh_token: Optional[RefreshToken] = None,
scope: Optional[Scopes] = None,
redirect_uri: Optional[URI] = None,
code_verifier: Optional[CodeVerifier] = None,
) -> CreateTokenResponse
Creates and returns access and refresh tokens for clients that are authenticated using client secrets. The access token can be used to fetch short-lived credentials for the assigned AWS accounts or to access application APIs using bearer authentication.
Parameters:
-
client_id(ClientId) –The unique identifier string for the client or application. This value comes from the result of the RegisterClient API.
-
client_secret(ClientSecret) –A secret string generated for the client. This value should come from the persisted result of the RegisterClient API.
-
grant_type(GrantType) –Supports the following OAuth grant types: Authorization Code, Device Code, and Refresh Token. Specify one of the following values, depending on the grant type that you want:
* Authorization Code -
authorization_code* Device Code -
urn:ietf:params:oauth:grant-type:device_code* Refresh Token -
refresh_token -
device_code(Optional[DeviceCode], default:None) –Used only when calling this API for the Device Code grant type. This short-lived code is used to identify this authorization request. This comes from the result of the StartDeviceAuthorization API.
-
code(Optional[AuthCode], default:None) –Used only when calling this API for the Authorization Code grant type. The short-lived code is used to identify this authorization request.
-
refresh_token(Optional[RefreshToken], default:None) –Used only when calling this API for the Refresh Token grant type. This token is used to refresh short-lived tokens, such as the access token, that might expire.
For more information about the features and limitations of the current IAM Identity Center OIDC implementation, see Considerations for Using this Guide in the IAM Identity Center OIDC API Reference.
-
scope(Optional[Scopes], default:None) –The list of scopes for which authorization is requested. This parameter has no effect; the access token will always include all scopes configured during client registration.
-
redirect_uri(Optional[URI], default:None) –Used only when calling this API for the Authorization Code grant type. This value specifies the location of the client or application that has registered to receive the authorization code.
-
code_verifier(Optional[CodeVerifier], default:None) –Used only when calling this API for the Authorization Code grant type. This value is generated by the client and presented to validate the original code challenge value the client passed at authorization time.
Raises:
-
AccessDeniedException–You do not have sufficient access to perform this action.
-
AuthorizationPendingException–Indicates that a request to authorize a client with an access user session token is pending.
-
ExpiredTokenException–Indicates that the token issued by the service is expired and is no longer valid.
-
InternalServerException–Indicates that an error from the service occurred while trying to process a request.
-
InvalidClientException–Indicates that the
clientIdorclientSecretin the request is invalid. For example, this can occur when a client sends an incorrectclientIdor an expiredclientSecret. -
InvalidGrantException–Indicates that a request contains an invalid grant. This can occur if a client makes a CreateToken request with an invalid grant type.
-
InvalidRequestException–Indicates that something is wrong with the input to the request. For example, a required parameter might be missing or out of range.
-
InvalidScopeException–Indicates that the scope provided in the request is invalid.
-
SlowDownException–Indicates that the client is making the request too frequently and is more than the service can handle.
-
UnauthorizedClientException–Indicates that the client is not currently authorized to make the request. This can happen when a
clientIdis not issued for a public client. -
UnsupportedGrantTypeException–Indicates that the grant type in the request is not supported by the service.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
Call OAuth/OIDC /token endpoint for Device Code grant with Secret authentication
>>> await client.create_token(client_id='_yzkThXVzLWVhc3QtMQEXAMPLECLIENTID', client_secret='VERYLONGSECRETeyJraWQiOiJrZXktMTU2NDAyODA5OSIsImFsZyI6IkhTMzg0In0', grant_type='urn:ietf:params:oauth:grant-type:device-code', device_code='yJraWQiOiJrZXktMTU2Njk2ODA4OCIsImFsZyI6IkhTMzIn0EXAMPLEDEVICECODE')
Call OAuth/OIDC /token endpoint for Refresh Token grant with Secret authentication
>>> await client.create_token(client_id='_yzkThXVzLWVhc3QtMQEXAMPLECLIENTID', client_secret='VERYLONGSECRETeyJraWQiOiJrZXktMTU2NDAyODA5OSIsImFsZyI6IkhTMzg0In0', grant_type='refresh_token', refresh_token='aorvJYubGpU6i91YnH7Mfo-AT2fIVa1zCfA_Rvq9yjVKIP3onFmmykuQ7E93y2I-9Nyj-A_sVvMufaLNL0bqnDRtgAkc0:MGUCMFrRsktMRVlWaOR70XGMFGLL0SlcCw4DiYveIiOVx1uK9BbD0gvAddsW3UTLozXKMgIxAJ3qxUvjpnlLIOaaKOoa/FuNgqJVvr9GMwDtnAtlh9iZzAkEXAMPLEREFRESHTOKEN', scope=['codewhisperer:completions'])
Source code in docs_src/capo_sso_oidc/_services/async_ssooidc.py
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 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |