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

Token refreshing #52

Closed
kakky opened this issue Oct 9, 2013 · 8 comments
Closed

Token refreshing #52

kakky opened this issue Oct 9, 2013 · 8 comments

Comments

@kakky
Copy link

kakky commented Oct 9, 2013

How do I refresh token?

Writing old django-social-auth style

user = User.objects.get(...)
social = user.social_auth.filter(provider='google-oauth2')[0]
social.refresh_token()

but,
<type 'exceptions.TypeError'> refresh_token() takes at least 2 arguments (1 given)

at /social/storage/base/UserMixin.refresh_token()
How do I get strategy param?

@omab
Copy link
Owner

omab commented Oct 9, 2013

using load_strategy() at social.apps.django_app.utils.

@kakky
Copy link
Author

kakky commented Oct 9, 2013

at refresh_token() method

self.get_key_and_secret()  # return (None, None)
self.setting('KEY')  # return ('SOCIAL_AUTH_KEY', 'SOCIAL_AUTH_KEY', 'KEY', 'KEY') ... There is no SOCIAL_AUTH_GOOGLE_OAUTH2_KEY
BACKENDSCACHE  # return {}

So I wrote

from social.apps.django_app.utils import load_strategy
from social.backends.utils import load_backends

user = User.objects.get(...)
social = user.social_auth.filter(provider='google-oauth2')[0]

load_backends(settings.AUTHENTICATION_BACKENDS)
strategy = load_strategy(backend=social.provider)

social.refresh_token(strategy)

Something wrong?

@kakky
Copy link
Author

kakky commented Oct 9, 2013

I think it is this (if self.REFRESH_TOKEN_METHOD == 'POST')

at social.backends.oauth.BaseOAuth2

    def refresh_token(self, token, *args, **kwargs):
#        params = self.refresh_token_params(token, *args, **kwargs)
        data = self.refresh_token_params(token, *args, **kwargs)
        request = self.request(self.REFRESH_TOKEN_URL or self.ACCESS_TOKEN_URL,
#                               params=params, headers=self.auth_headers(),
                               data=data, headers=self.auth_headers(),
                               method=self.REFRESH_TOKEN_METHOD)
        return self.process_refresh_token_response(request, *args, **kwargs)

@omab
Copy link
Owner

omab commented Oct 9, 2013

I see your code but not an error explanation, what happens when you run that code? What do you mean with "There is no SOCIAL_AUTH_GOOGLE_OAUTH2_KEY"? That's a needed setting to enable google-oauth2 backend.

@kakky
Copy link
Author

kakky commented Oct 10, 2013

Problem is

1.Perhaps, forget to load the backend instances in load_strategy().

2.If I do not specify a backend name, it is not possible to load the backend origin key and secret. Which backend should be use, maybe guess in refresh_token().

not work. can not find 'SOCIAL_AUTH_' + 'BACKEND_NAME' + '_KEY'

from social.apps.django_app.utils import load_strategy

user = User.objects.get(...)
social = user.social_auth.filter(provider='backend-name')[0]
strategy = load_strategy()
social.refresh_token(strategy)

work

from social.apps.django_app.utils import load_strategy

user = User.objects.get(...)
social = user.social_auth.filter(provider='backend-name')[0]
strategy = load_strategy(backend='backend-name')
social.refresh_token(strategy)

3.Though POST, It becomes the query parameter in the URL.

Sorry about funny English.

@omab
Copy link
Owner

omab commented Oct 10, 2013

@kakky, I've checked the process, the problem was the parameters being passed to the request, since Google OAuth2 uses POST the parameters should be passed in the data argument instead of params. This is fixed now, could you test and close the ticket if looks OK?

@kakky
Copy link
Author

kakky commented Oct 10, 2013

Thank you. It worked!

@kakky kakky closed this as completed Oct 10, 2013
@omab
Copy link
Owner

omab commented Oct 10, 2013

No problem!

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