You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.6 KiB

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);
}
}
}