def authenticate(self, **kwargs):
        headers = {'content-type': 'application/x-www-form-urlencoded'}
        endpoint_url = self.__get_token_endpoint()
        data = None

        if self.redirect:
            if 'code' not in kwargs:
                raise AuthenticationFailed(
                    "You first need to use the get_auth_uri() to get the 'code'"
                )

            code = kwargs['code']
            data = self.__get_token_using_code_params(code)
        else:
            data = self.__get_token_using_password_params()

        response = utils.send_request('POST',
                                      self.httplib,
                                      endpoint_url,
                                      headers,
                                      data=data)

        access_token = response['access_token']
        instance_url = response['instance_url']

        return Authentication(access_token, instance_url)
    def authenticate(self, **kwargs):
        if 'code' in kwargs:
            if not self.__login_api:
                raise AuthenticationFailed(
                    "You first need to use the get_auth_uri() to get the 'code'"
                )

        else:
            self.__login_api = login_api = LoginWithRestAPI(
                self.httplib, self.url_resources, **kwargs)

        return self.__login_api.authenticate(**kwargs)
Exemplo n.º 3
0
    def authenticate(self, **kwargs):
        headers = {'content-type': 'application/x-www-form-urlencoded'}
        endpoint_url = self.__get_token_endpoint()
        data = None

        # In some scenarios maybe is interesting to just inject the access_token and try to execute the
        # petition, adding the logic on the request to catch the RESPONSE_CODE_EXPIRED_SESSION Exception
        # and in case that a refresh token is provided, refresh the token and execute the action again
        #
        #  if 'access_token' in kwargs:
        #          if refresh_token' in kwargs:
        #              return Authentication(kwargs['access_token'], instance_url, kwargs['refresh_token'])
        #          else:
        #              return Authentication(kwargs['access_token'], instance_url)
        if 'refresh_token' in kwargs:
            data = self.__get_token_using_refresh_token_params(kwargs['refresh_token'])
        else:
            if self.redirect:
                if 'code' not in kwargs:
                    raise AuthenticationFailed("You first need to use the get_auth_uri() to get the 'code'")
                data = self.__get_token_using_code_params(kwargs['code'])
            else:
                data = self.__get_token_using_password_params()

        response = utils.send_request('POST',
                                      self.httplib,
                                      endpoint_url,
                                      headers,
                                      data=data)

        refresh_token = ''
        if 'refresh_token' in response:
            refresh_token = response['refresh_token']
        access_token = response['access_token']
        instance_url = response['instance_url']

        return Authentication(access_token, instance_url, refresh_token)
Exemplo n.º 4
0
    def authenticate_and_call(self, *args, **kwargs):
        if self.auth is None or not self.auth.is_authenticated():
            raise AuthenticationFailed("You need to first authentificate!")

        return func(self, *args, **kwargs)