我有一个用 AngularJS 编写的应用程序,它通过 oauth 2 联系 Web API 进行身份验证。该核心部分一切正常,但我需要传递其他参数来评估登录 (clientID) 并设置记住我类型功能(记住)。
从 Angular 方面来看,它看起来像这样:
var data = "grant_type=password&username=" + form.username + "&password=" + form.password + "&clientID=" + clientID + "&remember=" + form.remember;
var deferred = $q.defer();
$http.post(serviceBase + 'token', data, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }).success(function (response) {
当我通过 Startup.cs 和 SimpleAuthorizationServerProvider.cs 处理令牌时,有什么想法可以作为捕获这些值的最佳方法吗?谢谢
使用时GrantResourceOwnerCredentials
,您可以从以下位置检索 OWIN 请求OAuthGrantResourceOwnerCredentialsContext
并通过调用提取您需要的自定义参数ReadFormAsync()
.
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
var form = await context.Request.ReadFormAsync();
if (string.Equals(form["remember"], "true", StringComparison.OrdinalIgnoreCase))
{
// Add custom logic to handle the "remember me" case.
}
}
也就是说,通常不鼓励添加自定义(即非标准)参数,特别是如果它们是强制性的。请注意,您不需要使用自定义clientID
参数,因为已经有一个标准的等效参数:client_id
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)