Ejemplo n.º 1
0
 def _remote_exchange_payload(self, _db, code):
     library = self.library(_db)
     return dict(
         code=code,
         grant_type='authorization_code',
         redirect_uri=OAuthController.oauth_authentication_callback_url(
             library.short_name))
Ejemplo n.º 2
0
    def remote_exchange_code_for_bearer_token(self, _db, code):
        """Ask the OAuth provider to convert a code (passed in to the OAuth
        callback) into a bearer token.

        We can use the bearer token to act on behalf of a specific
        patron. It also gives us confidence that the patron
        authenticated correctly with Clever.

        :return: A ProblemDetail if there's a problem; otherwise, the
        bearer token.
        """
        payload = dict(
            code=code,
            grant_type='authorization_code',
            redirect_uri=OAuthController.oauth_authentication_callback_url(
                _db))
        authorization = base64.b64encode(self.client_id + ":" +
                                         self.client_secret)
        headers = {
            'Authorization': 'Basic %s' % authorization,
            'Content-Type': 'application/json',
        }
        response = self._get_token(payload, headers)
        invalid = INVALID_CREDENTIALS.detailed(
            _("A valid Clever login is required."))
        if not response:
            return invalid
        token = response.get('access_token', None)
        if not token:
            return invalid
        return token
Ejemplo n.º 3
0
 def _remote_exchange_payload(self, _db, code):
     library = self.library(_db)
     return dict(
         code=code,
         grant_type='authorization_code',
         redirect_uri=OAuthController.oauth_authentication_callback_url(
             library.short_name
         )
     )