简体   繁体   English

通过在弹出窗口中使用Owin外部登录来登录Asp.net

[英]Asp.net Login providers by using Owin external login In a Pop Up Window

I'm using MVC with Owin external login. 我正在将MVC与Owin外部登录一起使用。

Owin doesn't open login as popup. Owin不会打开登录名作为弹出窗口。 It redirects the page to that login provider. 它将页面重定向到该登录提供程序。

For example If i want to login through facebook it will not open facebook login in a popup window rather it redirects to facebook login page. 例如,如果我要通过Facebook登录,它将不会在弹出窗口中打开Facebook登录,而是重定向到Facebook登录页面。

So far with my R&D i have found that I have to create an authentication provider for Facebook. 到目前为止,我的研发工作已经发现我必须为Facebook创建一个身份验证提供程序。 So create a class that inherits from FacebookAuthenticationProvider. 因此,创建一个从FacebookAuthenticationProvider继承的类。 Within this class, override the "ApplyRedirect" method. 在此类内,重写“ ApplyRedirect”方法。

Here is my sample code : 这是我的示例代码:

public class FacebookProvider : FacebookAuthenticationProvider
{
    public override void ApplyRedirect(FacebookApplyRedirectContext context)
    {
        context.Response.Redirect(context.RedirectUri + "&display=popup");
    }
}

and i wire this code in my startup.auth.cs class like this: 然后将此代码连接到我的startup.auth.cs类中:

 app.UseFacebookAuthentication(new FacebookAuthenticationOptions
        {
            Provider = new FacebookProvider(), 
            AppId = "xxxxxxxxxx",
            AppSecret = "647e05af9188a8a3ccd0793aae9a846f",
            Scope = { "email" },
            SignInAsAuthenticationType = Microsoft.Owin.Security.AppBuilderSecurityExtensions.GetDefaultSignInAsAuthenticationType(app)
        });

and my _ExternalLoginListPartial.cshtml is like this: 和我的_ExternalLoginListPartial.cshtml是这样的:

 @using Microsoft.Owin.Security <h4>Use another service to log in.</h4> <hr /> @{ var loginProviders = Context.GetOwinContext().Authentication.GetExternalAuthenticationTypes(); if (loginProviders.Count() == 0) { <div> <p> There are no external authentication services configured. See <a href="http://go.microsoft.com/fwlink/?LinkId=403804">this article</a> for details on setting up this ASP.NET application to support logging in via external services. </p> </div> } else { using (Html.BeginForm("ExternalLogin", "CustomerAccount", new { ReturnUrl = Model.ReturnUrl })) { @Html.AntiForgeryToken() <div id="socialLoginList"> <p> @foreach (AuthenticationDescription p in loginProviders) { <button type="submit" class="btn btn-default" id="@p.AuthenticationType" name="provider" value="@p.AuthenticationType" title="Log in using your @p.Caption account">@p.AuthenticationType</button> } </p> </div> } } } 

So if there is any way i can solve my problem.. i have spend like 5 days to solve this issue .. 所以如果有什么办法我可以解决我的问题..我已经花了5天时间来解决这个问题..

What you are doing right now is telling Facebook to display the login page as if it was in a popup. 您现在正在做的就是告诉Facebook将登录页面显示为弹出窗口。 You are not doing anything to actually display a popup. 您没有做任何实际显示弹出窗口的操作。

If you were to wire your button tag onclick event to this function: 如果要将button标签的onclick事件连接到此功能:

<button onclick="return loginPopup('@Model.MyUrl');">My button</button>
function loginPopup(url) {
    var w = window.open(url,'name','height=200,width=150');
    if (window.focus) {
        w.focus();
    }
    return false;
}

Then, we would be closer to have something working. 然后,我们将更接近有一些工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM