Update 07082021
This commit is contained in:
43
WebFormApp/Account/OpenAuthProviders.ascx.cs
Normal file
43
WebFormApp/Account/OpenAuthProviders.ascx.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.Owin.Security;
|
||||
|
||||
namespace WebFormApp.Account
|
||||
{
|
||||
public partial class OpenAuthProviders : System.Web.UI.UserControl
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (IsPostBack)
|
||||
{
|
||||
var provider = Request.Form["provider"];
|
||||
if (provider == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Umleitung an den externen Anmeldeanbieter anfordern
|
||||
string redirectUrl = ResolveUrl(String.Format(CultureInfo.InvariantCulture, "~/Account/RegisterExternalLogin?{0}={1}&returnUrl={2}", IdentityHelper.ProviderNameKey, provider, ReturnUrl));
|
||||
var properties = new AuthenticationProperties() { RedirectUri = redirectUrl };
|
||||
// XSRF-Überprüfung beim Verknüpfen von Konten hinzufügen
|
||||
if (Context.User.Identity.IsAuthenticated)
|
||||
{
|
||||
properties.Dictionary[IdentityHelper.XsrfKey] = Context.User.Identity.GetUserId();
|
||||
}
|
||||
Context.GetOwinContext().Authentication.Challenge(properties, provider);
|
||||
Response.StatusCode = 401;
|
||||
Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
public string ReturnUrl { get; set; }
|
||||
|
||||
public IEnumerable<string> GetProviderNames()
|
||||
{
|
||||
return Context.GetOwinContext().Authentication.GetExternalAuthenticationTypes().Select(t => t.AuthenticationType);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user