gpt4 book ai didi

oauth - AuthenticationProperties 在基于 token 的身份验证中不起作用

转载 作者:行者123 更新时间:2023-12-02 06:31:17 25 4
gpt4 key购买 nike

我在我的项目中使用基于 OAuth Bearer token 的身份验证。成功登录请求后,我收到以下 json。

{"access_token":"some token","token_type":"bearer","expires_in":1232}

我想在下面的 json 中发送更多信息数据。我创建了身份验证票并添加了身份验证属性。但这并非不起作用。

GrantResourceOwnerCredentials 方法代码:

public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
try
{
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
var schoolId = context.UserName;
var password = context.Password;
logger.InfoFormat(CommonConstants.LoginInfoLogMessageFormat, schoolId);
var loginOperator = new LoginManager();
var result = loginOperator.IsUser(schoolId, password);
if (result)
{
var identity = new ClaimsIdentity(context.Options.AuthenticationType);
identity.AddClaim(new Claim("sub", context.UserName));
identity.AddClaim(new Claim("role", "user"));
var authenticationProperties = GetUserAuthenticationProperties();
var authenticationTicket = new AuthenticationTicket(identity, authenticationProperties);
context.Validated(authenticationTicket);
}
else
{
context.SetError("invalid_grant", "Kullanıcı adı veya şifre yanlış.");
}
}
catch (Exception exception)
{
logger.ErrorFormat("An error occured GrantResourceOwnerCredentials() method: {0}", exception);
}

}

GetUserAuthenticationProperties 方法代码:

private AuthenticationProperties GetUserAuthenticationProperties()
{
IDictionary<string, string> authenticationInformation = new Dictionary<string, string>();
authenticationInformation.Add("batuhan", "avlayan");
authenticationInformation.Add("fuat", "bugra");
return new AuthenticationProperties(authenticationInformation);
}

最佳答案

重写 TokenEndpoint 方法。

    public override Task TokenEndpoint(OAuthTokenEndpointContext context)
{
foreach (KeyValuePair<string, string> property in context.Properties.Dictionary)
{
context.AdditionalResponseParameters.Add(property.Key, property.Value);
}
return Task.FromResult<object>(null);
}

关于oauth - AuthenticationProperties 在基于 token 的身份验证中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35614270/

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