外部登录时“redirect_uri缺失或太长”

时间:2017-03-09 21:55:53

标签: asp.net .net-core identityserver4

只有在使用外部登录时我才会得到:

fail: IdentityServer4.Validation.AuthorizeRequestValidator[0]
      redirect_uri is missing or too long

客户端配置中的redirect_uri为“http://localhost:1234/signin-callback”,但使用密码登录时不会出现此错误。

    [HttpGet]
    public IActionResult ExternalLogin(string provider, string returnUrl = null)
    {
        var redirectUrl = Url.Action("ExternalLoginCallback", "Controller", new { ReturnUrl = returnUrl });
        var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
        return Challenge(properties, provider);
    }

    [HttpGet]
    public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
    {
        if (remoteError != null)
        {
            return BadRequest(remoteError);
        }
        var info = await _signInManager.GetExternalLoginInfoAsync();
        if (info == null)
        {
            return BadRequest("no login info");
        }
        var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false);
        if (result.Succeeded)
        {
            return Redirect(returnUrl); // debug gets to here where we redirect to "/connect/authorize/login?client_id=my-client"
        }
        return BadRequest();
    }

此代码成功登录,但当它重定向到“/ connect / authorize / login?client_id = my-client”时,它会返回错误。我应该寻找什么?

1 个答案:

答案 0 :(得分:4)

我发布问题太快了。

它需要重定向到/connect/authorize/login?client_id=my-client&redirect_uri=http://localhost:1234/signin-callback而不仅仅是/connect/authorize/login?client_id=my-client

我需要ExternalLogin()时传递/ExternalLogin?provider=[provider]&returnUrl=[plain text url with escaping '&'] /ExternalLogin?provider=[provider]&returnUrl=[encoded url]