Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth2Session.add_token() does not exist #11

Closed
nfvs opened this issue Jan 9, 2018 · 4 comments
Closed

OAuth2Session.add_token() does not exist #11

nfvs opened this issue Jan 9, 2018 · 4 comments

Comments

@nfvs
Copy link
Contributor

nfvs commented Jan 9, 2018

  File "/Users/nsantos/.virtualenvs/oauth/lib/python3.6/site-packages/authlib/client/oauth2.py", line 293, in request
    url, headers, data, self.token_placement
TypeError: 'NoneType' object is not callable

This is the snippet that triggers that (in request()):

            url, headers, data = self.add_token(
                self.token['access_token'],
                url, headers, data, self.token_placement
            )

OAuth2Session.add_token does not exist (it's None).

@nfvs
Copy link
Contributor Author

nfvs commented Jan 9, 2018

Sorry it actually exists as a property, but it was returning None:

    @property
    def add_token(self):
        if not self.token:
            return None

        token_type = self.token['token_type'].lower()
        if token_type == 'bearer':
            return add_bearer_token

I followed the docs and had token_type="oauth1.0", which was making that function return None.

@lepture
Copy link
Owner

lepture commented Jan 9, 2018

@nfvs OAuth2Session is designed for OAuth 2. Currently, it only supports bearer token.

I followed the docs and had token_type="oauth1.0"

Where did you find this in the documentation? It must be a mistake.

Are you trying OAuth 1? Then you should use OAuth1Session.

@nfvs
Copy link
Contributor Author

nfvs commented Jan 9, 2018

I'm using OAuth 2 actually. My mistake, the model only has OAUTH1_TOKEN_TYPE = 'oauth1.0': https://docs.authlib.org/en/latest/client/frameworks.html#cache-database

I'm storing the tokens in flask's session cookie, right after calling authorize_access_token(), and then in fetch_token I was just hardcoding a token_type.

@nfvs nfvs closed this as completed Jan 9, 2018
@lepture
Copy link
Owner

lepture commented Jan 9, 2018

@nfvs It is not safe to store a token in session cookies. If you are just doing it for testing, that's ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants