Beispiel #1
0
    def saveAuthorizationCode(self, code, REQUEST=None):
        """ """
        data = {
            'grant_type': 'authorization_code',
            'client_id': os.environ['GOOGLE_AUTH_CLIENT_ID'],
            'client_secret': os.environ['GOOGLE_AUTH_CLIENT_SECRET'],
            'code': code,
            'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob',
            'scope': GOOGLE_SCOPE,
        }
        resp = requests.post(GOOGLE_TOKEN_URI, data)
        self._save_access_token(resp)

        if REQUEST is not None:
            REQUEST.RESPONSE.redirect(self.absolute_url() + '/admin_account')
Beispiel #2
0
    def saveAuthorizationCode(self, code, REQUEST=None):
        """ """
        data = {
            'grant_type': 'authorization_code',
            'client_id': os.environ['GOOGLE_AUTH_CLIENT_ID'],
            'client_secret': os.environ['GOOGLE_AUTH_CLIENT_SECRET'],
            'code': code,
            'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob',
            'scope': GOOGLE_SCOPE,
        }
        resp = requests.post(GOOGLE_TOKEN_URI, data)
        self._save_access_token(resp)

        if REQUEST is not None:
            REQUEST.RESPONSE.redirect(self.absolute_url() + '/admin_account')
Beispiel #3
0
    def _update_access_token(self):
        if self._google_access_token is None:
            raise RuntimeError("Google access token is not set.")
        access_token, expiry = self._google_access_token
        if time.time() > expiry:
            code = self._google_refresh_token
            data = {
                'grant_type': 'refresh_token',
                'client_id': os.environ['GOOGLE_AUTH_CLIENT_ID'],
                'client_secret': os.environ['GOOGLE_AUTH_CLIENT_SECRET'],
                'refresh_token': code,
            }
            resp = requests.post(GOOGLE_TOKEN_URI, data)
            self._save_access_token(resp)
            access_token, expiry = self._google_access_token

        return access_token
Beispiel #4
0
    def _update_access_token(self):
        if self._google_access_token is None:
            raise RuntimeError("Google access token is not set.")
        access_token, expiry = self._google_access_token
        if time.time() > expiry:
            code = self._google_refresh_token
            data = {
                'grant_type': 'refresh_token',
                'client_id': os.environ['GOOGLE_AUTH_CLIENT_ID'],
                'client_secret': os.environ['GOOGLE_AUTH_CLIENT_SECRET'],
                'refresh_token': code,
            }
            resp = requests.post(GOOGLE_TOKEN_URI, data)
            self._save_access_token(resp)
            access_token, expiry = self._google_access_token

        return access_token