简体   繁体   中英

Python oauth/flask, how to pass arguments from decorated function

I need to call the method of @oauth.token_handler internally from flask. The signature is as follow:

@oauth.token_handler
def access_token(*args, **kwargs):
    return None

So it calls internally the implementation of token_handler(). I try to call

response = access_token("", {'grant_type':'password'})

Wishing that oauth can retrieve the arguments in the method, but it doesn't work.

400 {"error": "unsupported_grant_type"}

Oauth don't find the data (without surprise for me)

When a curl method work as expected:

curl -k -X POST -d "client_id=f9O7kapzXnK1gYAxxxxxxx&grant_type=password&username=blah&password=pass" http://localhost:5001/oauth/token

My question is, how to fake this call to oauth internally in order that it can retrieve all the information (grant_type, client_id, etc...). Because for the moment, I tryed with no luck.

Note: I know oauth should be called from the client side; But here, the process is that a person send me his/her provider credential for his/her id profil, I check if the credential is ok, and then I create an internal account with my own oauth provider and send them the access_token to the ressource of my application. My problem here is that I don't know how to call access_token() with the right parameter. Flask-oauth can't find my arguments.

Doc can be found here: http://flask-oauthlib.readthedocs.io/en/latest/api.html

I'm the author of Flask-OAuthlib. I have to say, it is not well designed, I strongly suggest that you use Authlib . Here is an example of OAuth 2 provider .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM