Flask 密码授予中的电子邮件而不是用户名

Flask 密码授予中的电子邮件而不是用户名,flask,oauth-2.0,authlib,Flask,Oauth 2.0,Authlib,我尝试在ResourceOwnerPasswordCredentialsGrant中使用电子邮件而不是用户名 我希望请求是这样的 curl -u client_id:client_secret -XPOST http://127.0.0.1:5000/oauth/token -F grant_type=password -F email=example@example.com -F password=password -F scope=read 但是我得到了一个错误{“error”:“无效的请

我尝试在ResourceOwnerPasswordCredentialsGrant中使用电子邮件而不是用户名 我希望请求是这样的

curl -u client_id:client_secret -XPOST http://127.0.0.1:5000/oauth/token -F grant_type=password -F email=example@example.com -F password=password -F scope=read

但是我得到了一个错误{“error”:“无效的请求”,“错误描述”:“请求中缺少用户名”。}

ResourceOwnerPasswordCredentialsGrant只支持
username
password
作为请求参数。如果您希望支持
电子邮件
,最好将
资源所有者PasswordCredentialsGrant
自定义为:

def authenticate_user(self, username, password):
    if '@' in username:
        user = get_user_by_email(username)
    else:
        user = get_user_by_username(username)
    if user.check_password(password):
        return user
您仍然应该使用参数
用户名
进行请求