Пример #1
0
 def get_user_email_from_iam(self, accessToken):
     header = {
         ZohoOAuthConstants.AUTHORIZATION:
         (ZohoOAuthConstants.OAUTH_HEADER_PREFIX + accessToken)
     }
     connector = ZohoOAuthHTTPConnector.get_instance(
         ZohoOAuth.get_user_info_url(), None, header, None,
         ZohoOAuthConstants.REQUEST_METHOD_GET)
     response = connector.trigger_request()
     return response.json()['Email']
Пример #2
0
 def get_connector(self, url):
     connector = ZohoOAuthHTTPConnector.get_instance(url, {})
     connector.add_http_request_params(ZohoOAuthConstants.CLIENT_ID,
                                       ZohoOAuthClient.oAuthParams.clientID)
     connector.add_http_request_params(
         ZohoOAuthConstants.CLIENT_SECRET,
         ZohoOAuthClient.oAuthParams.clientSecret)
     connector.add_http_request_params(
         ZohoOAuthConstants.REDIRECT_URL,
         ZohoOAuthClient.oAuthParams.redirectUri)
     return connector
Пример #3
0
 def get_user_email_from_iam(self, accessToken):
     header = {
         ZohoOAuthConstants.AUTHORIZATION:
         (ZohoOAuthConstants.OAUTH_HEADER_PREFIX + accessToken)
     }
     connector = ZohoOAuthHTTPConnector.get_instance(
         ZohoOAuth.get_user_info_url(), None, header, None,
         ZohoOAuthConstants.REQUEST_METHOD_GET)
     response = connector.trigger_request()
     try:
         response_json = response.json()
         if 'Email' in response_json:
             return response.json()['Email']
     except ValueError as err:
         raise ZohoOAuthException(
             'Exception while fetching User email from access token, Make sure AAAserver.profile.Read scope is included while generating the Grant token'
         )
Пример #4
0
    def get_refresh_token_user_email(self, grant_token):
        """
        :param code:
        :return:
        """
        try:
            params = {
                'code':
                grant_token,
                'client_id':
                ZohoOAuth.configProperties[ZohoOAuthConstants.CLIENT_ID],
                'client_secret':
                ZohoOAuth.configProperties[ZohoOAuthConstants.CLIENT_SECRET],
                'redirect_uri':
                ZohoOAuth.configProperties[ZohoOAuthConstants.REDIRECT_URL],
                'grant_type':
                'authorization_code'
            }
            http_connector = ZohoOAuthHTTPConnector.get_instance(
                ZohoOAuth.get_token_url(),
                params=params,
                method=ZohoOAuthConstants.REQUEST_METHOD_POST)
            response = http_connector.trigger_request()
            responseJSON = response.json()

            if (ZohoOAuthConstants.ACCESS_TOKEN in responseJSON):
                oAuthTokens = self.get_tokens_from_json(responseJSON)
                oAuthTokens.set_user_email(
                    self.get_user_email_from_iam(oAuthTokens.accessToken))
                ZohoOAuth.get_persistence_instance().saveOAuthTokens(
                    oAuthTokens)

                return oAuthTokens.refreshToken, oAuthTokens.userEmail
            else:
                raise ZohoOAuthException(
                    "Exception occured while fetching refresh token from Grant Token; Response is:"
                    + str(responseJSON))

        except ZohoOAuthException as ex:
            OAuthLogger.add_log(
                "Exception occured while generating refresh token",
                logging.ERROR, ex)
            raise ex