Skip to content

Auth

Auth

The Auth class is used to manage handle authentication with the Sonetel system. It can be used to create, refresh and fetch tokens.

It contains the following methods:

  • create_token() - Create an API access token from the user's Sonetel email address and password.
  • get_access_token() - Get the access token.
  • get_decoded_token() - Get the decoded access token.
  • get_refresh_token() - Get the refresh token.

Auth

Authentication class. Create, refresh and fetch tokens.

create_token(refresh_token='', grant_type='password', refresh='yes')

Create an API access token from the user's Sonetel email address and password. Optionally, generate a refresh token. Set the grant_type to refresh_token to refresh an existing access token.

Documentation: https://docs.sonetel.com/docs/sonetel-documentation/YXBpOjExMzI3NDM3-authentication

:param refresh: Optional. Flag to return refresh token in the response. Accepted values 'yes' and 'no'. Defaults to 'yes' :param grant_type: Optional. The OAuth2 grant type - password and refresh_token accepted. Defaults to 'password' :param refresh_token: Optional. Pass the refresh_token generated from a previous request in this field to generate a new access_token.

:return: dict. The access token and refresh token if the request was processed successfully. If the request failed, the error message is returned.

get_access_token()

Returns the access token.

Examples:

>>> from sonetel import Auth
>>> auth = Auth('username', 'password')
>>> auth.get_access_token()
'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhcGkuc29uZXRlbC5jb20iLCJleHAiOjE2MjQwNjY0NzgsImlhdCI6MTYyNDA2Mzg3OCwiaXNzIjoic29uZXRlbC5jb20iLCJqdGkiOiIyMjIyMjIiLCJzdWIiOiJzb25l'

Returns:

Name Type Description
access_token str

The access token that can be used to access other account resources.

get_decoded_token()

Decodes the access token and returns the decoded token.

Note: This method only decodes the payload - it does not verify the signature.

Examples:

>>> from sonetel import Auth
>>> auth = Auth('username', 'password')
>>> auth.get_decoded_token()
{'aud': 'api.sonetel.com', 'exp': 1624066478, 'iat': 1624063878, 'iss': 'sonetel.com', 'jti': '222222', 'sub': 'sonetel'}

Returns:

Name Type Description
dict

The decoded token.

get_refresh_token()

Return the refresh token that can be exchanged for a new access token.

Examples:

>>> from sonetel import Auth
>>> auth = Auth('username', 'password')
>>> auth.get_refresh_token()
'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhcGkuc29uZXRlbC5jb20iLCJleHAiOjE2MjQwNjY0NzgsImlhdCI6MTYyNDA2Mzg3OCwiaXNzIjoic29uZXRlbC5jb20iLCJqdGkiOiIyMjIyMjIiLCJzdWIiOiJzb25l'

Returns:

Name Type Description
str

The refresh token.