public void GetSetString() { var props = new AuthenticationProperties(); Assert.Null(props.GetString("foo")); Assert.Equal(0, props.Items.Count); props.SetString("foo", "foo bar"); Assert.Equal("foo bar", props.GetString("foo")); Assert.Equal("foo bar", props.Items["foo"]); Assert.Equal(1, props.Items.Count); props.SetString("foo", "foo baz"); Assert.Equal("foo baz", props.GetString("foo")); Assert.Equal("foo baz", props.Items["foo"]); Assert.Equal(1, props.Items.Count); props.SetString("bar", "xy"); Assert.Equal("xy", props.GetString("bar")); Assert.Equal("xy", props.Items["bar"]); Assert.Equal(2, props.Items.Count); props.SetString("bar", string.Empty); Assert.Equal(string.Empty, props.GetString("bar")); Assert.Equal(string.Empty, props.Items["bar"]); props.SetString("foo", null); Assert.Null(props.GetString("foo")); Assert.Equal(1, props.Items.Count); }
protected internal virtual AuthenticationProperties CreateAuthenticationProperties(string returnUrl, string scheme) { var authenticationProperties = new AuthenticationProperties { RedirectUri = this.Url.Action(nameof(Callback)) }; // This is mainly for ActiveLogin-handlers authenticationProperties.SetString("cancelReturnUrl", this.Url.Action("SignIn", "Account", new { returnUrl })); authenticationProperties.SetString(nameof(returnUrl), returnUrl); authenticationProperties.SetString(nameof(scheme), scheme); return(authenticationProperties); }
public IActionResult Login(string returnUrl) { var methodIsAvailable = _authenticationPluginManager .IsPluginActive(FacebookAuthenticationDefaults.SystemName, _workContext.CurrentCustomer, _storeContext.CurrentStore.Id); if (!methodIsAvailable) { throw new NopException("Facebook authentication module cannot be loaded"); } if (string.IsNullOrEmpty(_facebookExternalAuthSettings.ClientKeyIdentifier) || string.IsNullOrEmpty(_facebookExternalAuthSettings.ClientSecret)) { throw new NopException("Facebook authentication module not configured"); } //configure login callback action var authenticationProperties = new AuthenticationProperties { RedirectUri = Url.Action("LoginCallback", "FacebookAuthentication", new { returnUrl = returnUrl }) }; authenticationProperties.SetString(FacebookAuthenticationDefaults.ErrorCallback, Url.RouteUrl("Login", new { returnUrl })); return(Challenge(authenticationProperties, FacebookDefaults.AuthenticationScheme)); }
protected internal virtual AuthenticationProperties CreateAuthenticationProperties(string returnUrl, string scheme) { var authenticationProperties = new AuthenticationProperties { RedirectUri = this.Url.Action(nameof(this.Callback)) }; authenticationProperties.SetString(nameof(returnUrl), returnUrl); authenticationProperties.SetString(nameof(scheme), scheme); foreach (var decorator in this.DecorationLoader.GetAuthenticationPropertiesDecoratorsAsync(scheme).Result) { decorator.DecorateAsync(scheme, authenticationProperties, returnUrl); } return(authenticationProperties); }
protected internal virtual async Task <AuthenticationProperties> CreateAuthenticationPropertiesAsync(string authenticationScheme, string returnUrl) { var authenticationProperties = new AuthenticationProperties { RedirectUri = this.Url.Action(nameof(this.Callback)) }; authenticationProperties.SetString(AuthenticationKeys.ReturnUrl, returnUrl); authenticationProperties.SetString(AuthenticationKeys.Scheme, authenticationScheme); foreach (var decorator in await this.Facade.DecorationLoader.GetAuthenticationPropertiesDecoratorsAsync(authenticationScheme)) { await decorator.DecorateAsync(authenticationScheme, authenticationProperties, returnUrl); } return(authenticationProperties); }
public async Task LoginWithGoogle(string returnUrl = "/") { var properties = new AuthenticationProperties { RedirectUri = returnUrl }; properties.SetString("connection", "google-oauth2"); await HttpContext.ChallengeAsync("Auth0", properties); }
public IActionResult Login(string returnUrl) { var authenticationProperties = new AuthenticationProperties { RedirectUri = Url.Action("LoginCallback", "IdentityServerAuthentication", new { returnUrl = returnUrl }) }; authenticationProperties.SetString("ErrorCallback", Url.RouteUrl("Login", new { returnUrl })); return(Challenge(authenticationProperties, OpenIdConnectDefaults.AuthenticationScheme)); }
public IActionResult SignInAdmin() { var scheme = OpenIdConnectDefaults.AuthenticationScheme; var redirectUrl = Url.Content("~/"); var authProps = new AuthenticationProperties { RedirectUri = redirectUrl }; authProps.SetString("prompt", "admin_consent"); return(Challenge(authProps, scheme)); }
public virtual async Task DecorateAsync(string authenticationScheme, AuthenticationProperties properties, string returnUrl) { try { if (properties == null) { throw new ArgumentNullException(nameof(properties)); } if (!this.IsActiveLoginAuthenticationScheme(authenticationScheme)) { return; } var defaultScheme = this.AuthenticationOptions.Value.DefaultScheme; if (string.IsNullOrWhiteSpace(defaultScheme)) { return; } var cookieAuthenticationOptions = this.CookieAuthenticationOptionsMonitor.Get(defaultScheme); var cancelUrlBuilder = new UriBuilder { Path = cookieAuthenticationOptions.LoginPath }; if (!string.IsNullOrWhiteSpace(returnUrl)) { var queryString = HttpUtility.ParseQueryString(cancelUrlBuilder.Query); queryString.Set(nameof(returnUrl), returnUrl); // ReSharper disable AssignNullToNotNullAttribute cancelUrlBuilder.Query = queryString.ToString(); // ReSharper restore AssignNullToNotNullAttribute } properties.SetString("cancelReturnUrl", cancelUrlBuilder.Uri.PathAndQuery); await Task.CompletedTask.ConfigureAwait(false); } catch (Exception exception) { const string message = "Could not decorate active-login-authentication-properties."; this.Logger.LogErrorIfEnabled(exception, message); throw new InvalidOperationException(message, exception); } }
public async Task <ActionResult> Login(LoginModel u) { if (ModelState.IsValid) //verifica se é válido { var result = await _signInManager.PasswordSignInAsync(u.Username, u.Password, u.RememberMe, false); if (result.Succeeded) { var user = await _userManager.FindByEmailAsync(u.Username); var authProperties = new AuthenticationProperties { AllowRefresh = true, IsPersistent = u.RememberMe, IssuedUtc = DateTime.UtcNow, ExpiresUtc = (u.RememberMe ? DateTime.UtcNow.AddMonths(3) : DateTime.UtcNow.AddMinutes(30)) }; authProperties.Items.Add("Username", u.Username); authProperties.SetString(".persistent", u.RememberMe.ToString()); authProperties.Items.Add("Id", user.Id.ToString()); authProperties.Items.Add("Email", user.Email); await _signInManager.SignInAsync(user, authProperties, CookieAuthenticationDefaults.AuthenticationScheme); _logger.LogInformation($"Usuário {u.Username} efetuou o login com sucesso."); if (!string.IsNullOrEmpty(u.ReturnUrl) && Url.IsLocalUrl(u.ReturnUrl)) { return(Redirect(u.ReturnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { _logger.LogInformation($"Usuário {u.Username} Usuário ou Senha Inválidos."); ModelState.AddModelError("", "User or Password is invalid!"); } } return(View(u)); }
public async Task <IActionResult> Login(string returnUrl, string authentication) { if (!await _authenticationPluginManager.IsPluginActiveAsync(AuthenticationDefaults.PluginSystemName)) { throw new NopException("Authentication module cannot be loaded"); } //configure login callback action var socialMediaList = new SocialMediaList(); var authenticationProperties = new AuthenticationProperties { RedirectUri = "/" + socialMediaList.SocialMedias.Where(x => x.Name.ToLower() == authentication.ToLower()).Select(x => x.CallBackPath.ToLower()).FirstOrDefault() + "?returnUrl=" + returnUrl //Url.Action("LoginCallback", "Authentication", new { returnUrl = returnUrl }) }; authenticationProperties.SetString(AuthenticationDefaults.ErrorCallback, Url.RouteUrl("Login", new { returnUrl })); return(Challenge(authenticationProperties, authentication)); }
public IActionResult Login(string returnUrl) { if (!_externalAuthenticationService.ExternalAuthenticationMethodIsAvailable(FacebookAuthenticationDefaults.ProviderSystemName)) { throw new NopException("Facebook authentication module cannot be loaded"); } if (string.IsNullOrEmpty(_facebookExternalAuthSettings.ClientKeyIdentifier) || string.IsNullOrEmpty(_facebookExternalAuthSettings.ClientSecret)) { throw new NopException("Facebook authentication module not configured"); } //configure login callback action var authenticationProperties = new AuthenticationProperties { RedirectUri = Url.Action("LoginCallback", "FacebookAuthentication", new { returnUrl = returnUrl }) }; authenticationProperties.SetString("ErrorCallback", Url.RouteUrl("Login", new { returnUrl })); return(Challenge(authenticationProperties, FacebookDefaults.AuthenticationScheme)); }
public virtual async Task <IActionResult> Windows(string returnUrl) { returnUrl = this.ResolveAndValidateReturnUrl(returnUrl); // Check if windows-authentication has already been requested and succeeded. var authenticateResult = await this.HttpContext.AuthenticateAsync(AuthenticationSchemes.Windows); // ReSharper disable All if (authenticateResult.Principal is WindowsPrincipal windowsPrincipal) { var authenticationProperties = new AuthenticationProperties { RedirectUri = this.Url.Action(nameof(this.Callback)) }; authenticationProperties.SetString(AuthenticationKeys.ReturnUrl, returnUrl); authenticationProperties.SetString(AuthenticationKeys.Scheme, AuthenticationSchemes.Windows); var claims = windowsPrincipal.Claims .Where(claim => !claim.Type.Equals(ClaimTypes.DenyOnlySid, StringComparison.OrdinalIgnoreCase) && !claim.Type.Equals(ClaimTypes.GroupSid, StringComparison.OrdinalIgnoreCase) && !claim.Type.Equals(ClaimTypes.PrimaryGroupSid, StringComparison.OrdinalIgnoreCase) ) .ToList(); claims.Add(new Claim(ClaimTypes.NameIdentifier, "1")); try { var securityIdentifier = claims.FirstOrDefault(claim => claim.Type.Equals(ClaimTypes.PrimarySid, StringComparison.OrdinalIgnoreCase))?.Value; using (var principalContext = new PrincipalContext(ContextType.Domain)) { var userPrincipal = UserPrincipal.FindByIdentity(principalContext, IdentityType.Sid, securityIdentifier); if (userPrincipal == null) { throw new InvalidOperationException($"User-principal with security-identifier \"{securityIdentifier}\" was not found."); } var userPrincipalName = userPrincipal.UserPrincipalName; claims.Add(new Claim(ClaimTypes.Upn, userPrincipalName)); } } catch (Exception exception) { this.Logger.LogErrorIfEnabled(exception, "Could not get user-principal-name."); } var claimsIdentity = new ClaimsIdentity(claims, windowsPrincipal.Identity.AuthenticationType); await this.HttpContext.SignInAsync(AuthenticationSchemes.Intermediate, new ClaimsPrincipal(claimsIdentity), authenticationProperties); return(this.Redirect(authenticationProperties.RedirectUri)); } // ReSharper restore All // Trigger windows-authentication. Since windows-authentication don't support the redirect uri, this URL is re-triggered when we call challenge. return(this.Challenge(AuthenticationSchemes.Windows)); }