在 Asp.Net Identity 中设置 redirect_uri [英] Setting the redirect_uri in Asp.Net Identity

查看:18
本文介绍了在 Asp.Net Identity 中设置 redirect_uri的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为使用 Asp.Net Identity 的 facebook 登录设置 redirect_uri.但是,AccountController 中的 GetExternalLogin REST 方法仅在 redirect_uri 为/"时才会触发.如果我添加任何其他不会触发 GetExternalLogin 的内容,浏览器只会显示 error: invalid_request.

I am trying to set the redirect_uri for the facebook login with Asp.Net Identity. However, the GetExternalLogin REST method in the AccountController is only triggered if the redirect_uri is '/'. If I add anything else it does not trigger GetExternalLogin, the browser only shows error: invalid_request.

然而,url 包含重定向参数,因为它应该例如如果我将 redirect_uri 添加为 http://localhost:25432/testing

However the url contains the redirected parameter as it should e.g. if I add the redirect_uri as http://localhost:25432/testing

响应 URL 如下所示:

the response URL looks like this:

http://localhost:25432/api/Account/ExternalLogin?provider=Facebook&response_type=token&client_id=self&redirect_uri=http%3A%2F%2Flocalhost%3A25432%2Ftesting&state=0NctHHGq_aiazEurHYbvJT8hDgl0GJ_GGSdFfq2z5SA1

浏览器窗口显示:error: invalid_request
知道为什么这仅在重定向到/"而不是任何其他 url 时才有效?

and the browser window shows: error: invalid_request
Any idea why this works only when redirecting to '/' but not to any other url´s?

推荐答案

问题是 GetExternalLogin 注册为 OAuthOptions.AuthorizeEndpointPath 用于 app.UseOAuthBearerTokens(OAuthOptions).此配置对端点的参数进行验证.

The problem is that GetExternalLogin registered as OAuthOptions.AuthorizeEndpointPath which used for app.UseOAuthBearerTokens(OAuthOptions). This configuration puts validation on arguments of endpoint.

if (!Uri.TryCreate(authorizeRequest.RedirectUri, UriKind.Absolute, out validatingUri))
{
    // The redirection endpoint URI MUST be an absolute URI
}
else if (!String.IsNullOrEmpty(validatingUri.Fragment))
{
    // The endpoint URI MUST NOT include a fragment component.
}
else if (!Options.AllowInsecureHttp &&
                    String.Equals(validatingUri.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase))
{
    // The redirection endpoint SHOULD require the use of TLS
}

并且您应该传递授权端点请求缺少所需的 response_type 参数"和授权端点请求包含不受支持的 response_type 参数"

And you should pass "Authorize endpoint request missing required response_type parameter" and "Authorize endpoint request contains unsupported response_type parameter"

这篇关于在 Asp.Net Identity 中设置 redirect_uri的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆