【问题标题】:Access HTTP Post params in Flask while using SQLAlchemy使用 SQLAlchemy 访问 Flask 中的 HTTP Post 参数
【发布时间】:2017-10-16 19:37:06
【问题描述】:

我有使用 SQLAlchemy 和 JWT 令牌的烧瓶服务器。 我正在从包含 google-id-token 的客户端发送 HTTP 发布请求。

我是这样发送的:

@Headers( "Content-Type: application/json" )
    @POST("/auth")
    Call<JsonObject> getGenericJSON(@Body JsonObject obj);

在服务器上: 第一件事 - 请求到达安全文件:

从模型.用户导入用户模型

def authenticate(username, password):
    # user = username_mapping.get(username, None)
    print("DEBUG: username="+username)
    print("DEBUG: password="+password)
    user = UserModel.find_by_username(username)
    if user and user.password == password:
        print ("Returning User") #email, id, last_run, password, routes
        print (user)
        return user

def identity(payload): #unique for jwt. Takes in a payload - the token. We'll exctract the id from the payload, and get the user_id
    print("DEBUG: In identity")
    user_id = payload['identity']
    # return userid_mapping.get(user_id, None)
    return UserModel.find_by_id(user_id)

我想访问 google 令牌,但我不知道使用此 JWT 身份验证的 POST 请求在哪里。 但我找不到它。我知道这应该很简单。肯定会发送它,因为解析器需要它。谢谢。

编辑: 我试过了:

        request_data = User.parser.parse_args()

但它的 get 是用户 get 函数而不是 post 函数,所以它会崩溃......

【问题讨论】:

    标签: python flask retrofit jwt google-signin


    【解决方案1】:

    试试token = self.request_args.get('token')。将“令牌”替换为您发送令牌时使用的任何标识符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-09
      • 1970-01-01
      • 2021-06-25
      • 2018-06-24
      • 1970-01-01
      • 2014-01-31
      • 1970-01-01
      相关资源
      最近更新 更多