Я могу успешно войти в Facebook и позвонить
Код: Выделить всё
public async Task ExternalLoginCallback(string returnUrl)Код: Выделить всё
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();- У меня есть локальный хост, использующий https в Visual Studio 2017.
- Обновленные пакеты:
Microsoft.Owin - Microsoft.Owin.Security
- Microsoft.Owin.Security.Cookies
< /li>
Microsoft.Owin.Security.Facebook - Microsoft.Owin.Security.OAuth< /p>
[*] Настройте приложение входа в Facebook на веб-сайте разработчика Facebook, указав следующие значения
[img]https://i.sstatic.net /vgi4pro7.png[/img]
Добавлены адрес электронной почты для разрешения и public_profile.
Я использовал следующий код в файле start.auth.cs
Код: Выделить всё
public void ConfigureAuth(IAppBuilder app)
{
// Configure the db context, user manager and signin manager to use a single instance per request
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext(ApplicationUserManager.Create);
app.CreatePerOwinContext(ApplicationSignInManager.Create);
app.CreatePerOwinContext(ApplicationRoleManager.Create);
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
// Configure the sign in cookie
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseFacebookAuthentication(
appId: "000000000000000",
appSecret: "111111111111111111111111111");
}
Код: Выделить всё
public void ConfigureAuth(IAppBuilder app)
{
// Configure the db context, user manager and signin manager to use a single instance per request
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext(ApplicationUserManager.Create);
app.CreatePerOwinContext(ApplicationSignInManager.Create);
app.CreatePerOwinContext(ApplicationRoleManager.Create);
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
// Configure the sign in cookie
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
var facebookAuthenticationOptions = new FacebookAuthenticationOptions()
{
AppId = "0000000000000000000000",
AppSecret = "11111111111111111111111111111111111",
AuthenticationType = "Facebook",
SignInAsAuthenticationType = "ExternalCookie",
Scope = { "email", "public_profile" },
UserInformationEndpoint = "https://graph.facebook.com/v20.0/me?fields=id,name,email",
BackchannelHttpHandler = new FacebookBackChannelHandler(),
};
}
Это код из ExternalLoginCallback
Код: Выделить всё
[AllowAnonymous]
public async Task ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Login");
}
// Sign in the user with this external login provider if the user already has a login
var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false });
case SignInStatus.Failure:
default:
// If the user does not have an account, then prompt the user to create an account
//ViewBag.ReturnUrl = returnUrl;
ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email });
}
}
Спасибо
Подробнее здесь: https://stackoverflow.com/questions/787 ... oasync-ret