All of sudden few days ago i started getting this 401 error from Twitter
This seems similar to https://dev.twitter.com/discussions/16443 but I'm calling authorize() with callback and oauth_verifier param is passed.
I was having similar issue, found explicitly clearing out the oauth tokens in the session between authentication requests solved my issue. Did not find similar issue in facebook, which is why it was slightly confusing.
Hey @lucasvickers, how exactly did you clear out the oauth tokens in between requests? I've been running into similar issues.
Sorry for missing this update,
I used the code
where my oauth getter/setter references that key
fwiw, I'm seeing the same issue (with some automatic pingdom authentication to our app), I have yet to see the content of the exception (but I trapped it as I relate in #12). I'm not sure what @lucasvickers refers to, it seems that these session keys are specific to his app (flask_auth session data seems to be of the shape: self.name + '_oauthtok')
self.name + '_oauthtok'
I too am seeing this error if the user visits this route when they have already authenticated with twitter:
"""Calling into authorize will cause the OpenID auth machinery to kick
in. When all worked out as expected, the remote application will
redirect back to the callback URL provided.
next=request.args.get('next') or request.referrer or None))
I think I've worked around it by just checking for the existence of a token in the session and redirecting to an authenticated view.
I got one instance of this exception last night. The message (data) was: "Failed to exchange tokens"
Probably some lag on twitter side.
Just got the same issue with the callback failing with Invalid / expired Token. Resolved it with @lucasvickers advice by clearing explicitly the token in the session. Flask-OAuth==0.12
Invalid / expired Token