CognitoIdentityProvider / Client / list_user_sessions
list_user_sessions¶
- CognitoIdentityProvider.Client.list_user_sessions(**kwargs)¶
Lists the active sessions for the currently signed-in user. Amazon Cognito authorizes this operation with the user’s access token and returns all of the user’s active sessions across every app client in the user pool, including both token sessions and SSO sessions. The
IsCurrentSessionfield identifies the session that the calling access token belongs to. The results are eventually consistent, and new sessions are typically included within a few seconds.See also: AWS API Documentation
Request Syntax
response = client.list_user_sessions( AccessToken='string', NextToken='string' )
- Parameters:
AccessToken (string) –
[REQUIRED]
A valid access token that Amazon Cognito issued to the user whose sessions you want to list. Amazon Cognito derives the user pool and username from this token.
NextToken (string) – A pagination token that Amazon Cognito returned in a previous response. Use this value to retrieve the next page of results if a
NextTokenwas included in a prior response.
- Return type:
dict
- Returns:
Response Syntax
{ 'Sessions': [ { 'SessionId': 'string', 'SessionType': 'TOKEN'|'SSO', 'ClientId': 'string', 'CreateDate': datetime(2015, 1, 1), 'LastActiveDate': datetime(2015, 1, 1), 'DeviceType': 'string', 'LastIPAddress': 'string', 'LastLocation': { 'City': 'string', 'Country': 'string' }, 'OriginSessionId': 'string', 'IsCurrentSession': True|False }, ], 'NextToken': 'string' }
Response Structure
(dict) –
Sessions (list) –
A list of the user’s active sessions. Each element describes one token session or SSO session.
(dict) –
Describes an active user session. Amazon Cognito returns this type in the responses of
ListUserSessionsandAdminListUserSessions, for both token sessions and SSO sessions.SessionId (string) –
The unique identifier for the session. This is a 28-character string of lowercase letters and digits, prefixed with
tknfor a token session orssofor an SSO session.SessionType (string) –
The type of the session. Valid values are
TOKENandSSO.ClientId (string) –
The ID of the app client that the session belongs to.
CreateDate (datetime) –
The date and time when the session was created.
LastActiveDate (datetime) –
The date and time of the most recent activity on the session. For a token session, this is the most recent token refresh or rotation; a new authentication creates a new token session rather than updating an existing one. For an SSO session, this is the most recent authentication, token grant, or token rotation.
DeviceType (string) –
A description of the device associated with the most recent activity on the session, derived from the parsed user agent (operating system and browser or app). Amazon Cognito overwrites this value on each sign-in, refresh, and rotation. The value can be
unknown. The maximum length is 1,024 characters.LastIPAddress (string) –
The IP address associated with the most recent activity on the session. Amazon Cognito overwrites this value on each refresh and rotation. The maximum length is 128 characters.
LastLocation (dict) –
The geographic location of the most recent activity on the session, derived from the IP address.
City (string) –
The city of the most recent activity on the session, derived from the IP address. This value can be null if geo-IP resolution fails. The maximum length is 256 characters.
Country (string) –
The country of the most recent activity on the session, derived from the IP address and returned in English (for example,
United States). This is a country name as returned by the geo-IP database, not an ISO country code, and can beunknownif geo-IP resolution fails.
OriginSessionId (string) –
For a token session, the ID of the SSO session that the token session originated from. This value is null for sessions that were initiated through the API and didn’t come through an SSO session. Amazon Cognito returns this value for token sessions only.
IsCurrentSession (boolean) –
Specifies whether this session matches the access token supplied in the request. This value is always
falsefor theAdminListUserSessionsoperation, which doesn’t take an access token.
NextToken (string) –
The pagination token to use in a subsequent request to retrieve the next page of results.
Exceptions
CognitoIdentityProvider.Client.exceptions.InvalidParameterExceptionCognitoIdentityProvider.Client.exceptions.ResourceNotFoundExceptionCognitoIdentityProvider.Client.exceptions.TooManyRequestsExceptionCognitoIdentityProvider.Client.exceptions.NotAuthorizedExceptionCognitoIdentityProvider.Client.exceptions.PasswordResetRequiredExceptionCognitoIdentityProvider.Client.exceptions.UserNotFoundExceptionCognitoIdentityProvider.Client.exceptions.UserNotConfirmedExceptionCognitoIdentityProvider.Client.exceptions.OperationNotEnabledExceptionCognitoIdentityProvider.Client.exceptions.InternalErrorExceptionCognitoIdentityProvider.Client.exceptions.ForbiddenException