def get_access_token(self):
        """

        Generates an access token and refresh token that you may use to
        call Onelogin's API methods.

        Returns the generated OAuth Token info
        :return: OAuth Token info
        :rtype: OneLoginToken

        See https://developers.onelogin.com/api-docs/1/oauth20-tokens/generate-tokens Generate Tokens documentation.

        """
        self.clean_error()

        try:
            url = self.get_url(Constants.TOKEN_REQUEST_URL)

            data = {
                'grant_type': 'client_credentials'
            }

            headers = self.get_authorized_headers(bearer=False)

            response = requests.post(url, headers=headers, json=data)
            if response.status_code == 200:
                data = response.json()
                if 'status' in data:
                    self.error = str(data['status']['code'])
                    self.error_description = self.extract_error_message_from_response(response)
                else:
                    token = OneLoginToken(response.json())
                    self.access_token = token.access_token
                    self.refresh_token = token.refresh_token
                    self.expiration = token.created_at + datetime.timedelta(seconds=token.expires_in)
                    return token
            else:
                self.error = str(response.status_code)
                self.error_description = self.extract_error_message_from_response(response)
        except Exception as e:
            self.error = 500
            self.error_description = e.args[0]
def get_access_token ( self ) : self . clean_error ( ) try : url = self . get_url ( Constants . TOKEN_REQUEST_URL ) data = { 'grant_type' : 'client_credentials' } headers = self . get_authorized_headers ( bearer = False ) response = requests . post ( url , headers = headers , json = data ) if response . status_code == 200 : data = response . json ( ) if 'status' in data : self . error = str ( data [ 'status' ] [ 'code' ] ) self . error_description = self . extract_error_message_from_response ( response ) else : token = OneLoginToken ( response . json ( ) ) self . access_token = token . access_token self . refresh_token = token . refresh_token self . expiration = token . created_at + datetime . timedelta ( seconds = token . expires_in ) return token else : self . error = str ( response . status_code ) self . error_description = self . extract_error_message_from_response ( response ) except Exception as e : self . error = 500 self . error_description = e . args [ 0 ]
Generates an access token and refresh token that you may use to
        call Onelogin's API methods.

        Returns the generated OAuth Token info
        :return: OAuth Token info
        :rtype: OneLoginToken

        See https://developers.onelogin.com/api-docs/1/oauth20-tokens/generate-tokens Generate Tokens documentation.