Ejemplo n.º 1
0
    def __call__(self, r):
        if self.bearer_type == BEARER_HEADER:
            r.headers = tokens.prepare_bearer_headers(self.token, r.headers)
        elif self.bearer_type == BEARER_BODY:
            r.data = tokens.prepare_bearer_body(self.token, r.data)
        elif self.bearer_type == BEARER_URI:
            r.url = tokens.prepare_bearer_uri(self.token, r.url)
        elif callable(self.bearer_type):
            r = self.bearer_type(self.token, r)

        return r
Ejemplo n.º 2
0
    def __call__(self, r):
        if self.bearer_type == BEARER_HEADER:
            r.headers = tokens.prepare_bearer_headers(self.token, r.headers)
        elif self.bearer_type == BEARER_BODY:
            r.data = tokens.prepare_bearer_body(self.token, r.data)
        elif self.bearer_type == BEARER_URI:
            r.url = tokens.prepare_bearer_uri(self.token, r.url)
        elif callable(self.bearer_type):
            r = self.bearer_type(self.token, r)

        return r
Ejemplo n.º 3
0
    def _add_bearer_token(self, uri, http_method='GET', body=None,
            headers=None, token_placement=None):
        """Add a bearer token to the request uri, body or authorization header."""
        if token_placement == AUTH_HEADER:
            headers = tokens.prepare_bearer_headers(self.access_token, headers)

        elif token_placement == URI_QUERY:
            uri = tokens.prepare_bearer_uri(self.access_token, uri)

        elif token_placement == BODY:
            body = tokens.prepare_bearer_body(self.access_token, body)

        else:
            raise ValueError("Invalid token placement.")
        return uri, headers, body
Ejemplo n.º 4
0
    def _add_bearer_token(self,
                          uri,
                          http_method='GET',
                          body=None,
                          headers=None,
                          token_placement=None):
        """Add a bearer token to the request uri, body or authorization header."""
        if token_placement == AUTH_HEADER:
            headers = tokens.prepare_bearer_headers(self.access_token, headers)

        elif token_placement == URI_QUERY:
            uri = tokens.prepare_bearer_uri(self.access_token, uri)

        elif token_placement == BODY:
            body = tokens.prepare_bearer_body(self.access_token, body)

        else:
            raise ValueError("Invalid token placement.")
        return uri, headers, body