我使用MVC和Owin外部登录。
Owin不会以弹出窗口的身份登录。 它将页面重定向到该登录提供程序。
例如 如果我想通过Facebook登录,它将无法在弹出窗口中打开Facebook登录,而是重定向到Facebook登录页面。
到目前为止,我的R& D发现我必须为Facebook创建一个身份验证提供程序。因此,创建一个继承自FacebookAuthenticationProvider的类。在这个课程中,覆盖" ApplyRedirect"方法
以下是我的示例代码:
public class FacebookProvider : FacebookAuthenticationProvider
{
public override void ApplyRedirect(FacebookApplyRedirectContext context)
{
context.Response.Redirect(context.RedirectUri + "&display=popup");
}
}
我将这段代码连接到我的startup.auth.cs类中,如下所示:
app.UseFacebookAuthentication(new FacebookAuthenticationOptions
{
Provider = new FacebookProvider(),
AppId = "xxxxxxxxxx",
AppSecret = "647e05af9188a8a3ccd0793aae9a846f",
Scope = { "email" },
SignInAsAuthenticationType = Microsoft.Owin.Security.AppBuilderSecurityExtensions.GetDefaultSignInAsAuthenticationType(app)
});
和我的_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>
}
}
}
&#13;
所以,如果有任何办法可以解决我的问题..我花了5天时间来解决这个问题..
答案 0 :(得分:0)
您现在正在做的是告诉Facebook显示登录页面,就像它在弹出窗口中一样。你没有做任何事情来实际上显示一个弹出窗口。
如果您要将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;
}
然后,我们会更接近工作。