ASP.NET Web API标识外部登录重定向

时间:2015-09-24 05:13:19

标签: asp.net-web-api asp.net-identity-2

我正在使用ASP.net webAPI身份进行Facebook登录,我有angularjs应用程序

当我打电话

MainURL + 'api/Account/ExternalLogins?returnUrl=%2F&generateState=true'

我不想返回Web API页面,而是希望Facebook将我重定向回我的angularJS应用程序,所以我这样做了:

 [AllowAnonymous]
    [Route("ExternalLogins")]
    public IEnumerable<ExternalLoginViewModel> GetExternalLogins(string returnUrl, bool generateState = false)
    {
        IEnumerable<AuthenticationDescription> descriptions = Authentication.GetExternalAuthenticationTypes();
        List<ExternalLoginViewModel> logins = new List<ExternalLoginViewModel>();

        string state;

        if (generateState)
        {
            const int strengthInBits = 256;
            state = RandomOAuthStateGenerator.Generate(strengthInBits);
        }
        else
        {
            state = null;
        }

        foreach (AuthenticationDescription description in descriptions)
        {
            ExternalLoginViewModel login = new ExternalLoginViewModel
            {
                Name = description.Caption,
                Url = Url.Route("ExternalLogin", new
                {
                    provider = description.AuthenticationType,
                    response_type = "token",
                    client_id = Startup.PublicClientId,
                    redirect_uri = new Uri("http://localhost:6263/com.html").AbsoluteUri,
                   // redirect_uri = new Uri(Request.RequestUri, returnUrl).AbsoluteUri,
                    state = state
                }),
                State = state
            };
            logins.Add(login);
        }

        return logins;
    }

redirect_uri = new Uri(“http://localhost:6263/com.html”)。AbsoluteUri,

但浏览器给我一个错误 enter image description here

来自服务的回应是:

/api/Account/ExternalLogin?provider=Facebook&response_type=token&client_id=self&redirect_uri=localhost%3A6263%2Fcom.html&state=j0y0wF0yhvA_tzqbJo0GijCecqfbNWT0vLQiXxcHDqM1

1 个答案:

答案 0 :(得分:0)

我确定这已经很晚了。看看你的网址,它有一个双斜杠(//)

相关问题