简体   繁体   English

Python oauth / flask,如何从修饰函数传递参数

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

I need to call the method of @oauth.token_handler internally from flask. 我需要从flask内部调用@ oauth.token_handler的方法。 The signature is as follow: 签名如下:

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

So it calls internally the implementation of token_handler(). 因此,它在内部调用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. 希望oauth可以检索方法中的参数,但是不起作用。

400 {"error": "unsupported_grant_type"}

Oauth don't find the data (without surprise for me) Oauth找不到数据(对我来说并不奇怪)

When a curl method work as expected: 当curl方法按预期方式工作时:

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...). 我的问题是,如何在内部伪造此对oauth的调用,以便它可以检索所有信息(grant_type,client_id等)。 Because for the moment, I tryed with no luck. 因为暂时,我没有运气尝试。

Note: I know oauth should be called from the client side; 注意:我知道oauth应该从客户端调用; 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. 但是在这里,过程是一个人向我发送了他/她的身份证明文件的提供者凭据,我检查了该凭据是否正常,然后使用自己的oauth提供者创建了一个内部帐户,并将access_token发送给我的应用程序的资源。 My problem here is that I don't know how to call access_token() with the right parameter. 我的问题是我不知道如何使用正确的参数调用access_token()。 Flask-oauth can't find my arguments. Flask-oauth找不到我的参数。

Doc can be found here: http://flask-oauthlib.readthedocs.io/en/latest/api.html 可以在以下位置找到文档: http : //flask-oauthlib.readthedocs.io/en/latest/api.html

I'm the author of Flask-OAuthlib. 我是Flask-OAuthlib的作者。 I have to say, it is not well designed, I strongly suggest that you use Authlib . 我不得不说,它的设计不是很好,我强烈建议您使用Authlib Here is an example of OAuth 2 provider . 这是OAuth 2提供程序示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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