gpt4 book ai didi

c# - 如何将其他参数传递给 OWIN 登录?

转载 作者:太空狗 更新时间:2023-10-29 23:06:12 25 4
gpt4 key购买 nike

我有一个 ASP.NET Web API 站点,它正在执行 OWIN 身份验证,传递用户名和密码,它们神奇地出现在我的 GrantResourceOwnerCredentials 方法中,位于 UserNameOAuthGrantResourceOwnerCredentialsContext 参数的 Password 属性。不知道这是如何工作的,但确实如此。

无论如何,现在我想将另一个参数传递给登录方法,我想在相同的 GrantResourceOwnerCredentials 方法中访问它。但是因为我不知道这个魔法是如何工作的,所以它从登录请求中获取 UserNamePassword 参数并将它们复制到 OAuthGrantResourceOwnerCredentialsContext参数,我现在不知道如何访问我的新参数。

我该怎么做?

最佳答案

尝试:

//read all parameters
IFormCollection parameters = await context.Request.ReadFormAsync();

if (parameters == null)
{
context.SetError("invalid_grant", "Invalid request");
return;
}
//get desired parameter
var deviceId = parameters.Get("device_id");
//check if it was send
if (deviceId == null)
{
context.SetError("invalid_grant", "parameter 'device_id' is required");
return;
}

基于:https://stackoverflow.com/a/21244952/965722

关于c# - 如何将其他参数传递给 OWIN 登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35580334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com