- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Asp.Net Identity 为 facebook 登录设置 redirect_uri。但是,AccountController
中的 GetExternalLogin
REST 方法仅在 redirect_uri 为“/”时才会触发。如果我添加任何其他内容,它不会触发 GetExternalLogin
,浏览器只会显示 error: invalid_request。
然而,url 包含重定向参数,因为它应该例如如果我将 redirect_uri 添加为 http://localhost:25432/testing
响应 URL 如下所示:
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 时有效吗?
最佳答案
对于可能遇到此问题的任何其他人:问题是当您从 Visual Studio SPA 模板中获取(复制)ApplicationOAuthProvider.cs
并且它位于此代码所在的位置时:
public override Task ValidateClientRedirectUri(OAuthValidateClientRedirectUriContext context)
{
if (context.ClientId == _publicClientId)
{
var expectedRootUri = new Uri(context.Request.Uri, "/");
if (expectedRootUri.AbsoluteUri == context.RedirectUri)
{
context.Validated();
}
}
return Task.FromResult<object>(null);
}
这显然会阻止任何看起来不像 http://localhost/
或 http://example.com/
的 redirect_uri
> 因此,例如 http://example.com/home
将不起作用。
下面是 Katana 中 InvokeAuthorizeEndpointAsync
的源代码,它完成了所有工作,您可以看到它调用了可能为此 MVC 注册的任何自定义 OAuthProvider
Web API 应用程序(此注册通常发生在 Startup.Auth.cs
中):
private async Task<bool> InvokeAuthorizeEndpointAsync()
{
var authorizeRequest = new AuthorizeEndpointRequest(Request.Query);
var clientContext = new OAuthValidateClientRedirectUriContext(
Context,
Options,
authorizeRequest.ClientId,
authorizeRequest.RedirectUri);
if (!String.IsNullOrEmpty(authorizeRequest.RedirectUri))
{
bool acceptableUri = true;
Uri validatingUri;
if (!Uri.TryCreate(authorizeRequest.RedirectUri, UriKind.Absolute, out validatingUri))
{
// The redirection endpoint URI MUST be an absolute URI
// http://tools.ietf.org/html/rfc6749#section-3.1.2
acceptableUri = false;
}
else if (!String.IsNullOrEmpty(validatingUri.Fragment))
{
// The endpoint URI MUST NOT include a fragment component.
// http://tools.ietf.org/html/rfc6749#section-3.1.2
acceptableUri = false;
}
else if (!Options.AllowInsecureHttp &&
String.Equals(validatingUri.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase))
{
// The redirection endpoint SHOULD require the use of TLS
// http://tools.ietf.org/html/rfc6749#section-3.1.2.1
acceptableUri = false;
}
if (!acceptableUri)
{
clientContext.SetError(Constants.Errors.InvalidRequest);
return await SendErrorRedirectAsync(clientContext, clientContext);
}
}
await Options.Provider.ValidateClientRedirectUri(clientContext);
if (!clientContext.IsValidated)
{
_logger.WriteVerbose("Unable to validate client information");
return await SendErrorRedirectAsync(clientContext, clientContext);
}
var validatingContext = new OAuthValidateAuthorizeRequestContext(
Context,
Options,
authorizeRequest,
clientContext);
if (string.IsNullOrEmpty(authorizeRequest.ResponseType))
{
_logger.WriteVerbose("Authorize endpoint request missing required response_type parameter");
validatingContext.SetError(Constants.Errors.InvalidRequest);
}
else if (!authorizeRequest.IsAuthorizationCodeGrantType &&
!authorizeRequest.IsImplicitGrantType)
{
_logger.WriteVerbose("Authorize endpoint request contains unsupported response_type parameter");
validatingContext.SetError(Constants.Errors.UnsupportedResponseType);
}
else
{
await Options.Provider.ValidateAuthorizeRequest(validatingContext);
}
if (!validatingContext.IsValidated)
{
// an invalid request is not processed further
return await SendErrorRedirectAsync(clientContext, validatingContext);
}
_clientContext = clientContext;
_authorizeEndpointRequest = authorizeRequest;
var authorizeEndpointContext = new OAuthAuthorizeEndpointContext(Context, Options);
await Options.Provider.AuthorizeEndpoint(authorizeEndpointContext);
return authorizeEndpointContext.IsRequestCompleted;
}
这是关键:
await Options.Provider.ValidateClientRedirectUri(clientContext);
因此,您的解决方案是更改 ValidateClientRedirectUri
执行验证的方式 - 如您所见,默认的 SPA 实现非常简单。
有很多人对 SPA 有疑问,主要是因为它缺少任何类型的有用信息,我的意思是对于 ASP.NET Identity 和 OWIN 的东西,以及关于 KnockoutJS 实现中发生的事情。
我希望 Microsoft 能为这些模板提供更全面的文档,因为任何尝试做更复杂的事情的人都会遇到问题。
我在这上面花了几个小时,深入研究 OWIN (Katana) 源代码,认为是上述实现阻止了我的重定向 URI,但事实并非如此,希望也能帮助其他人。
HTH
关于asp.net-mvc - 在 Asp.Net Identity 中设置 redirect_uri,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20693082/
我在SO上看过这里,并且找到了有关redirect_uri的几篇文章,但是我似乎无法弄清楚如何将Localhost用作我的重定向uri。希望任何人都可以向我解释。 亲切的问候, 最佳答案 您可以按照S
我们正在编写一个与 OAuth2 api 集成的插件。 棘手的部分是我们不能像在大多数集成中那样对重定向 URI 进行硬编码,因为客户端可以在他们控制的任何域上安装这个插件(想想 Wordpress
当我尝试从我的 api 访问 keycloak 来验证用户身份时,但它给我错误 Invalid parameter:iredirect_uri on keycloak page。我在师父之外创造了自己
类似的问题和答案都没有解决我的问题。 我有两个 Facebook 应用程序。一个是另一个的测试版本,因此它们几乎相同。我在测试中没有问题。但是在实时应用程序上,我收到“redirect_uri 不属于
我确信有一个相对简单的方法可以解决这个问题,但我需要一些帮助。我有一个登陆页面,它接受用户的电子邮件地址并生成一个唯一的 URL,用户可以使用该 URL 来推荐 friend 。我使用 AJAX 绑定
当我尝试通过网络在 Google Plus 中验证我的应用程序时,出现错误: 错误:invalid_requestredirect_uri 的参数值无效:缺少权限:MY_APP:/oauth2call
我通过在开发人员控制台注册我的项目获得了客户端 ID 和 API key 。并且在运行身份验证过程时出现这样的错误400. 这是一个错误。错误:redirect_uri_mismatch请求中的重定向
尝试登录身份服务器(使用 .net core 3 预览版)时,即使请求 uri 和允许的 uri 相同,我也会收到 Invalid redirect_uri 错误。 我还能做错什么? fail: Id
我有 keylcoak 的本地实例,我正在尝试将我的 flutter 应用程序连接到它,为此我正在关注 this tutorial但我被这个 redirect_uri 问题困住了。 在 android
我正在使用 Scribe API 实现 facebook 签名功能,但在提交 facebook 身份验证 url 后出现以下错误。 callback_url = http://localhost:18
我正在学习本教程 http://developers.facebook.com/docs/appsonfacebook/tutorial/特别是在这部分代码 $app_id = "YOUR_APP_
我在两台服务器上使用 facebook 应用程序,dev 和 live。开发服务器托管在 test.testdev.com,实时服务器托管在 test.teSTLive.net。早些时候它在两台服务器
我想在我的 iOS 应用程序中访问一些社交网络,例如 Instagram、Facebook、Twitter。我需要获取用户信息、他们的 friend 等。所有这些社交网络都使用 OAuth 2.0 来
我正在使用 linkedin 身份验证 api 来登录我的网站用户。 首先,我将重定向到以下 url: https://www.linkedin.com/oauth/v2/authorization?
我正在尝试将 Instagram 集成到 Android 应用程序中,并希望使用自定义架构,例如 - sociallogin://authorize 有没有办法在 Instagram 开发者门户中使用
我不断从 windows live 收到这个错误 The provided value for the input parameter 'redirect_uri' is not valid. The
目前我正尝试在我的网络应用程序上连接 paypal oauth 登录。但是我收到了这个错误 客户端代码 paypal.use(["login"], function (login) {
我正在尝试基于documentation使用React和Node开发一个应用程序: 我一步一步地按照本教程进行操作,但是我被困在使用此URL格式测试应用程序中: 我更换了ngrok地址和shopify
我如何编辑 redirect_uri在我的 SoundCloud 应用程序仪表板中?我去http://soundcloud.com/you/apps但没有找到编辑按钮。 最佳答案 目前无法进行编辑,因
我正在尝试让用户从我的 Flutter 应用登录到 Google API,但无法让它自动获取 token 。我最接近的是在授权屏幕中看到 token 字符串,并被要求将其复制/粘贴回应用程序。我怀疑它
我是一名优秀的程序员,十分优秀!