:doc:`SSOOIDC <../../sso-oidc>` / Client / create_token

************
create_token
************



.. py:method:: SSOOIDC.Client.create_token(**kwargs)

  

  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.

  

  See also: `AWS API Documentation <https://docs.aws.amazon.com/goto/WebAPI/sso-oidc-2019-06-10/CreateToken>`_  


  **Request Syntax**
  ::

    response = client.create_token(
        clientId='string',
        clientSecret='string',
        grantType='string',
        deviceCode='string',
        code='string',
        refreshToken='string',
        scope=[
            'string',
        ],
        redirectUri='string',
        codeVerifier='string'
    )
    
  :type clientId: string
  :param clientId: **[REQUIRED]** 

    The unique identifier string for the client or application. This value comes from the result of the  RegisterClient API.

    

  
  :type clientSecret: string
  :param clientSecret: **[REQUIRED]** 

    A secret string generated for the client. This value should come from the persisted result of the  RegisterClient API.

    

  
  :type grantType: string
  :param grantType: **[REQUIRED]** 

    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``

    

  
  :type deviceCode: string
  :param deviceCode: 

    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.

    

  
  :type code: string
  :param code: 

    Used only when calling this API for the Authorization Code grant type. The short-lived code is used to identify this authorization request.

    

  
  :type refreshToken: string
  :param refreshToken: 

    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 <https://docs.aws.amazon.com/singlesignon/latest/OIDCAPIReference/Welcome.html>`__.

    

  
  :type scope: list
  :param scope: 

    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.

    

  
    - *(string) --* 

    

  :type redirectUri: string
  :param redirectUri: 

    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.

    

  
  :type codeVerifier: string
  :param codeVerifier: 

    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.

    

  
  
  :rtype: dict
  :returns: 
    
    **Response Syntax**

    
    ::

      {
          'accessToken': 'string',
          'tokenType': 'string',
          'expiresIn': 123,
          'refreshToken': 'string',
          'idToken': 'string'
      }
      
    **Response Structure**

    

    - *(dict) --* 
      

      - **accessToken** *(string) --* 

        A bearer token to access Amazon Web Services accounts and applications assigned to a user.

        
      

      - **tokenType** *(string) --* 

        Used to notify the client that the returned token is an access token. The supported token type is ``Bearer``.

        
      

      - **expiresIn** *(integer) --* 

        Indicates the time in seconds when an access token will expire.

        
      

      - **refreshToken** *(string) --* 

        A token that, if present, can be used to refresh a previously issued access token that might have expired.

         

        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 <https://docs.aws.amazon.com/singlesignon/latest/OIDCAPIReference/Welcome.html>`__.

        
      

      - **idToken** *(string) --* 

        The ``idToken`` is not implemented or supported. 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 <https://docs.aws.amazon.com/singlesignon/latest/OIDCAPIReference/Welcome.html>`__.

         

        A JSON Web Token (JWT) that identifies who is associated with the issued access token.

        
  
  **Exceptions**
  
  *   :py:class:`SSOOIDC.Client.exceptions.InvalidRequestException`

  
  *   :py:class:`SSOOIDC.Client.exceptions.InvalidClientException`

  
  *   :py:class:`SSOOIDC.Client.exceptions.InvalidGrantException`

  
  *   :py:class:`SSOOIDC.Client.exceptions.UnauthorizedClientException`

  
  *   :py:class:`SSOOIDC.Client.exceptions.UnsupportedGrantTypeException`

  
  *   :py:class:`SSOOIDC.Client.exceptions.InvalidScopeException`

  
  *   :py:class:`SSOOIDC.Client.exceptions.AuthorizationPendingException`

  
  *   :py:class:`SSOOIDC.Client.exceptions.SlowDownException`

  
  *   :py:class:`SSOOIDC.Client.exceptions.AccessDeniedException`

  
  *   :py:class:`SSOOIDC.Client.exceptions.ExpiredTokenException`

  
  *   :py:class:`SSOOIDC.Client.exceptions.InternalServerException`

  