public void Authenticated(ClaimsIdentity identity, IDictionary <string, string> properties, IDictionary <string, object> description) { var descrip = new AuthenticationDescription(description); _accepted.Add(descrip.AuthenticationType); // may not match identity.AuthType _results.Add(new AuthenticationResult(identity, new AuthenticationProperties(properties), descrip)); }
public static AuthenticationDescriptionViewModel ToViewModel(this AuthenticationDescription ol) { return(new AuthenticationDescriptionViewModel() { AuthenticationType = ol.AuthenticationType, Caption = ol.Caption }); }
public static string GetIconClass(AuthenticationDescription provider) { if (provider.DisplayName == "Microsoft") { return("windows"); } return(provider.DisplayName.ToLower()); }
public SamlAuthenticationOptions() : base("SAML2") { Description = new AuthenticationDescription { AuthenticationType = "SAML2", Caption = "Saml 2.0 Authentication protocol for OWIN" }; MetadataPath = "/metadata"; }
/// <summary> /// Used during the External authentication process to retrieve external sign-in options /// that have been set with SetExternalAuthenticationOptions /// </summary> /// <param name="authenticationDescription"></param> public static ExternalSignInAutoLinkOptions GetExternalAuthenticationOptions(this AuthenticationDescription authenticationDescription) { if (authenticationDescription.Properties.ContainsKey("ExternalSignInAutoLinkOptions") == false) { return(null); } var options = authenticationDescription.Properties["ExternalSignInAutoLinkOptions"] as ExternalSignInAutoLinkOptions; return(options); }
public BlizzardAuthenticationOptions(string authenticationType) : base(authenticationType) { AuthenticationType = authenticationType; AuthenticationMode = AuthenticationMode.Active; Caption = "Blizzard"; Description = new AuthenticationDescription() { Caption = "Blizzard OAuth", AuthenticationType = "Blizzard" }; }
public static AuthenticationProperties GetSignInChallengeResult(this AuthenticationDescription authenticationDescription, IOwinContext ctx) { if (authenticationDescription.Properties.ContainsKey("ChallengeResultCallback") == false) { return(null); } var cb = authenticationDescription.Properties["ChallengeResultCallback"] as Func <IOwinContext, AuthenticationProperties>; if (cb == null) { return(null); } return(cb(ctx)); }
public SamlAuthenticationOptions() : base("SAML2") { Description = new AuthenticationDescription { AuthenticationType = "SAML2", Caption = "Saml 2.0 Authentication protocol for OWIN" }; SignInAsAuthenticationType = "SAML2"; MetadataPath = "/saml2/metadata"; LoginPath = "/saml2/login"; LogoutPath = "/saml2/logout"; GetFromCache = s => memoryCache.Get(s); SetInCache = (s, o, d) => memoryCache.Set(s, o, d); }
public WhenTargettingAnEmptyButtonTag() { _loginProvider = new AuthenticationDescription { DisplayName = "This is the display name", AuthenticationScheme = "This is the scheme" }; _tagHelper = new LoginProviderButtonTagHelper() { LoginProvider = _loginProvider }; _context = GetTagHelperContext(); _output = GetTagHelperOutput(); }
public static AuthenticationDescription ToAuthenticationDescription(this ApplicationAuthenticationDescription authenticationDescription) { if (authenticationDescription == null) { return(null); } var description = new AuthenticationDescription { AuthenticationType = authenticationDescription.AuthenticationType, Caption = authenticationDescription.Caption }; description.Properties.Clear(); foreach (var property in authenticationDescription.Properties) { description.Properties.Add(property.Key, property.Value); } return(description); }
UnassignOAuthProvider(AuthenticationDescription model) { var userId = _context.User.Identity.GetUserId(); var login = _userManager.GetLogins(userId) .FirstOrDefault(x => x.LoginProvider == model.AuthenticationType); var result = _userManager.RemoveLogin(userId, login); if (result.Succeeded) { var user = _userManager.FindById(userId); SignIn(user, isPersistent: false); RedirectToManager(ManageMessageId.RemoveLoginSuccess); return; } RedirectToManager(ManageMessageId.Error); }
private static IEnumerable <AuthenticationDescription> GetAuthenticationProviders(HttpContextBase httpContextBase) { if (SignInController.authenticationProviders == null) { IDictionary <string, IdentityProviderClientConfigurationElement> identityProviderDictionary = GetIdentityProvidersFromConfig(); List <AuthenticationDescription> authDescriptions = new List <AuthenticationDescription>(); foreach (AuthenticationDescription openIdConnectDescription in httpContextBase.GetOwinContext().Authentication.GetAuthenticationTypes().Where(t => t.Properties.ContainsKey(CookieConstants.Caption))) { KeyValuePair <string, object> authenticationType = openIdConnectDescription.Properties.Single(p => p.Key == CookieConstants.AuthenticationType); KeyValuePair <string, object> caption = openIdConnectDescription.Properties.Single(p => p.Key == CookieConstants.Caption); AuthenticationDescription authDescription = new AuthenticationDescription() { AuthenticationType = authenticationType.Value.ToString(), Caption = caption.Value.ToString() }; IdentityProviderClientConfigurationElement identityProvider = identityProviderDictionary[authDescription.AuthenticationType]; authDescription.Properties.Add(SignInController.ImageUrl, identityProvider.ImageUrl); authDescription.Properties.Add(SignInController.DisplayIndex, identityProvider.DisplayIndex); authDescriptions.Add(authDescription); } foreach (IdentityProviderClientConfigurationElement identityProvider in identityProviderDictionary.Values) { if (identityProvider.ProviderType == IdentityProviderType.ACS) { AuthenticationDescription authDescription = new AuthenticationDescription() { AuthenticationType = identityProvider.Name, Caption = identityProvider.Name }; authDescription.Properties.Add(SignInController.ImageUrl, identityProvider.ImageUrl); authDescription.Properties.Add(SignInController.DisplayIndex, identityProvider.DisplayIndex); authDescriptions.Add(authDescription); } } SignInController.authenticationProviders = authDescriptions.OrderBy(ad => ad.Properties[DisplayIndex]); } return(SignInController.authenticationProviders); }
private string CreateUrl(AuthenticationDescription description, string returnUrl, string state, bool isLinkable, bool isRegistration) { var url = Url.RouteFromController("ExternalLogin", ControllerContext.ControllerDescriptor.ControllerName, new { provider = description.AuthenticationType, organization = RequestedOrganization, response_type = "token", client_id = Startup.JsAppClientId, redirect_uri = new Uri(Request.RequestUri, $"{returnUrl}?authType={description.AuthenticationType}").AbsoluteUri, state = state, userId = isLinkable ? GetUserAndOrganization().UserId : null, isRegistration = isRegistration ? "true" : null }); return(url); }
private async Task <LoginPair> ToExternalAuthenticationTypes(int id, IList <UserLoginInfo> userLogins, AuthenticationDescription p, CancellationToken cancellationToken) { var loginProvider = await ToLoginProvider(p.AuthenticationType, cancellationToken); var user = userLogins.SingleOrDefault(u => u.LoginProvider == loginProvider); var authenticationType = user == null ? p.AuthenticationType : loginProvider; var properties = new Dictionary <string, object>(p.Properties, StringComparer.Ordinal); var provider = new AuthenticationDescription(properties) { AuthenticationType = authenticationType }; return(new LoginPair { Id = id, Provider = provider, User = user }); }
public static Microsoft.Owin.Security.AuthenticationDescription Create(AuthenticationDescription authDescrip) { if (authDescrip == null) { return(null); } var identityAuthDescription = new Microsoft.Owin.Security.AuthenticationDescription { AuthenticationType = authDescrip.AuthenticationType, Caption = authDescrip.Caption, }; foreach (var property in authDescrip.Properties) { identityAuthDescription.Properties.Add(property.Key, property.Value); } return(identityAuthDescription); }
AssignOAuthProvider(AuthenticationDescription model) { var properties = new AuthenticationProperties { RedirectUri = StateController .GetNavigationLink( "ExternalLoginHandler", new NavigationData { { ProviderNameKey, model.AuthenticationType }, { ReturnUrlKey, StateContext.Bag.ReturnUrl } }) }; if (_context.User.Identity.IsAuthenticated) { properties.Dictionary[XsrfKey] = _context.User.Identity.GetUserId(); } _authenticationManager.Challenge(properties, model.AuthenticationType); _response.StatusCode = 401; _response.End(); }
/// <summary> /// Initialize properties of AuthenticationOptions base class /// </summary> /// <param name="authenticationType">Assigned to the AuthenticationType property</param> protected AuthenticationOptions(string authenticationType) { Description = new AuthenticationDescription(); AuthenticationType = authenticationType; AuthenticationMode = AuthenticationMode.Active; }
private static void ConfigureIdentityProviders(IAppBuilder app, string signInAsType) { var desc = new AuthenticationDescription(); desc.Caption = "Google"; desc.AuthenticationType = "Google"; desc.Properties["Img"] = "<img>"; app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions { AuthenticationType = "Google", Caption = "Sign-in with Google", SignInAsAuthenticationType = signInAsType, Description = desc, ClientId = "28751939105-qp1ud0pms2pffpu9ssji6rhhpms45bhu.apps.googleusercontent.com", ClientSecret = "ul3fdy8YOi3nWmsdQ9rap6Vn" }); TwitterAuthenticationOptions twitterAuthenticationOptions = new TwitterAuthenticationOptions(); twitterAuthenticationOptions.ConsumerKey = "9w4EYvCfs9wjfqZDeCDll4ZBg"; twitterAuthenticationOptions.ConsumerSecret = "jcQ35Eo8ZjQMLVOddqwB0OyzUuTPN3h8XZrjm4kFZGOCOAWFas"; twitterAuthenticationOptions.Caption = "Sign-in with Twitter"; twitterAuthenticationOptions.SignInAsAuthenticationType = signInAsType; twitterAuthenticationOptions.BackchannelCertificateValidator = new Microsoft.Owin.Security.CertificateSubjectKeyIdentifierValidator(new[] { "A5EF0B11CEC04103A34A659048B21CE0572D7D47", // VeriSign Class 3 Secure Server CA - G2 "0D445C165344C1827E1D20AB25F40163D8BE79A5", // VeriSign Class 3 Secure Server CA - G3 "7FD365A7C2DDECBBF03009F34339FA02AF333133", // VeriSign Class 3 Public Primary Certification Authority - G5 "39A55D933676616E73A761DFA16A7E59CDE66FAD", // Symantec Class 3 Secure Server CA - G4 "add53f6680fe66e383cbac3e60922e3b4c412bed", // Symantec Class 3 EV SSL CA - G3 "4eb6d578499b1ccf5f581ead56be3d9b6744a5e5", // VeriSign Class 3 Primary CA - G5 "5168FF90AF0207753CCCD9656462A212B859723B", // DigiCert SHA2 High Assurance Server CA "B13EC36903F8BF4701D498261A0802EF63642BC3" // DigiCert High Assurance EV Root CA }); app.UseTwitterAuthentication(twitterAuthenticationOptions); MicrosoftAccountAuthenticationOptions microsoftAccountAuthenticationOptions = new MicrosoftAccountAuthenticationOptions(); microsoftAccountAuthenticationOptions.ClientId = "000000004018E347"; microsoftAccountAuthenticationOptions.ClientSecret = "MOqHuPKgbLngN6EHrR6IR0w7779tFLyb"; microsoftAccountAuthenticationOptions.Caption = "Sign-in with Microsoft"; microsoftAccountAuthenticationOptions.SignInAsAuthenticationType = signInAsType; app.UseMicrosoftAccountAuthentication(microsoftAccountAuthenticationOptions); var fa = new FacebookAuthenticationOptions() { Caption = "Sign-in with Facebook", SignInAsAuthenticationType = signInAsType, AppId = "1585563455100467", AppSecret = "ff9ab6a79875e037db94701e79c57f0d" }; fa.Scope.Add("email"); fa.Scope.Add("public_profile"); app.UseFacebookAuthentication(fa); //if (IdentityServer3AppSettings.AdditionalIdentityProvidersEnabled) //{ // // if google authentication is enabled. // if (GoogleAuthenticationAppSettings.Enabled) // { // } // LinkedInAuthenticationOptions linkedInAuthenticationOptions = new LinkedInAuthenticationOptions(); // linkedInAuthenticationOptions.ClientId = "77vc0fkijvxj8l"; // linkedInAuthenticationOptions.ClientSecret = "44ALEkiMBMc2rsSK"; // linkedInAuthenticationOptions.Caption = "Sign-in with LinkedIn"; // linkedInAuthenticationOptions.SignInAsAuthenticationType = signInAsType; // app.UseLinkedInAuthentication(linkedInAuthenticationOptions); //} }
private static System.Collections.Specialized.NameValueCollection CreateExternalLoginQueryString(string state, AuthenticationDescription description) { var nvc = System.Web.HttpUtility.ParseQueryString(string.Empty); nvc["provider"] = description.AuthenticationType; nvc["response_type"] = "token"; nvc["client_id"] = Startup.PublicClientId; nvc["redirect_uri"] = "www.google.com"; nvc["state"] = state; return(nvc); }
public static ExternalSignInAutoLinkOptions GetExternalAuthenticationOptions(this AuthenticationDescription authenticationDescription) => authenticationDescription.GetExternalSignInAutoLinkOptions();
//public void Configure(IAppBuilder app, ILoggerFactory loggerFactory) //{ // loggerFactory.AddConsole(); // app.Run(async (context) => // { // // создаем объект логгера // var logger = loggerFactory.CreateLogger("RequestInfoLogger"); // // пишем на консоль информацию // logger.LogInformation("Processing request {0}", context.Request.Path); // await context.Response.WriteAsync("Hello World!"); // }); //} // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app) { // Enable the application to use a cookie to store information for the signed in user app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login") }); // Use a cookie to temporarily store information about a user logging in with a third party login provider app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); // Uncomment the following lines to enable logging in with third party login providers //app.UseMicrosoftAccountAuthentication( // clientId: "", // clientSecret: ""); // app.UseTwitterAuthentication( // consumerKey: "", // consumerSecret: ""); app.UseVkontakteAuthentication(new Duke.Owin.VkontakteMiddleware.VkAuthenticationOptions() { AppId = "5539354", AppSecret = "BGyEyIukWrwycrE1IlhY" }); var fdesc = new AuthenticationDescription(); fdesc.Caption = "Google"; fdesc.AuthenticationType = "Google"; fdesc.Properties["Img"] = "<img>"; app.UseFacebookAuthentication( appId: "299636750382790", appSecret: "6b680d40392f580f4415f115de0172f9"); var gdesc = new AuthenticationDescription(); gdesc.Caption = "Google"; gdesc.AuthenticationType = "Google"; gdesc.Properties["Img"] = "<img>"; var googleOauth2Authentication = new GoogleOAuth2AuthenticationOptions() { Description = gdesc, ClientId = "590776490678-orlc0fur5hgdouhgd4rodf00qt9e6kau.apps.googleusercontent.com", ClientSecret = "aQvm8YcQ3BRxuyzMRYhnU4X9", Provider = new GoogleOAuth2AuthenticationProvider { OnAuthenticated = async context => { // Retrieve the OAuth access token to store for subsequent API calls string accessToken = context.AccessToken; // Retrieve the name of the user in Google string googleName = context.Name; // Retrieve the user's email address string googleEmailAddress = context.Email; } } }; googleOauth2Authentication.Scope.Add("email"); app.UseGoogleAuthentication(googleOauth2Authentication); }