public async Task <SsoResponse> Login([FromBody] LoginPost data) { try { var token = new PlexToken(data.Token); var(accessTier, loggedIn) = GetAccessTier(); if (!loggedIn) { accessTier = await _plexClient.GetAccessTier(serverIdentifier, token); } if (accessTier == AccessTier.Failure) { var loginFailureResponse = _authValidator.ValidateAuthenticationStatus(AccessTier.NoAccess, false, GetServiceName(), GetServiceUri(), string.Empty); Response.StatusCode = loginFailureResponse.Status; return(loginFailureResponse); } var user = await _plexClient.GetUserInfo(token); var claims = new List <Claim> { new Claim(Constants.AccessTierClaim, accessTier.ToString()), new Claim(Constants.AccessTokenClaim, token.Value), new Claim(Constants.ServerIdentifierClaim, serverIdentifier.Value), new Claim(Constants.UsernameClaim, user.Username), new Claim(Constants.EmailClaim, user.Email), new Claim(Constants.ThumbnailClaim, user.Thumbnail) }; var identity = new ClaimsIdentity( claims, CookieAuthenticationDefaults.AuthenticationScheme ); var authProperties = new AuthenticationProperties { AllowRefresh = true, IsPersistent = true }; await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity), authProperties ); var response = _authValidator.ValidateAuthenticationStatus(accessTier, true, GetServiceName(), GetServiceUri(), user.Username); Response.StatusCode = response.Status; return(response); } catch (Exception e) { _logger.LogError("Failed to log user in", e); var unhandledErrorResponse = _authValidator.ValidateAuthenticationStatus(AccessTier.NoAccess, false, GetServiceName(), GetServiceUri(), string.Empty, true); Response.StatusCode = unhandledErrorResponse.Status; return(unhandledErrorResponse); } }
public SsoResponse Get() { var response = _authValidator.ValidateAuthenticationStatus(Identity, ServiceName, ServiceUri); Response.StatusCode = response.Status; return(response); }
public async Task <SsoResponse> Login([FromBody] LoginPost data) { try { Identity.AccessToken = new AccessToken(data.Token); Identity.ServerIdentifier = _serverIdentifier; if (!Identity.IsAuthenticated) { Identity.AccessTier = await _plexClient.GetAccessTier(_serverIdentifier, Identity.AccessToken); } if (Identity.AccessTier == AccessTier.Failure) { Identity.AccessTier = AccessTier.NoAccess; Identity.IsAuthenticated = false; return(GetErrorResponse()); } var user = await _plexClient.GetUserInfo(Identity.AccessToken); Identity.Email = user.Email; Identity.Username = user.Username; Identity.Thumbnail = user.Thumbnail; Identity.IsAuthenticated = true; var identity = new ClaimsIdentity( Identity.AsClaims(), CookieAuthenticationDefaults.AuthenticationScheme ); var authProperties = new AuthenticationProperties { AllowRefresh = true, IsPersistent = true }; await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity), authProperties ); var response = _authValidator.ValidateAuthenticationStatus(Identity, ServiceName, ServiceUri); Response.StatusCode = response.Status; return(response); } catch (Exception e) { _logger.LogError("Failed to log user in", e); Identity.AccessTier = AccessTier.NoAccess; Identity.IsAuthenticated = false; return(GetErrorResponse()); } }
public SsoResponse Get() { var(accessTier, loggedIn) = GetAccessTier(); var serviceName = GetServiceName(); var serviceUri = GetServiceUri(); var userName = GetUserName(); var response = _authValidator.ValidateAuthenticationStatus(accessTier, loggedIn, serviceName, serviceUri, userName); Response.StatusCode = response.Status; return(response); }
public ActionResult <SsoResponse> Get() { var response = _authValidator.ValidateAuthenticationStatus(Identity, ServiceName, ServiceUri); Response.StatusCode = response.Status; if (response.AccessBlocked) { return(LocalRedirect($"/{ServiceName}")); } return(response); }
public SsoResponse Get() { var response = _authValidator.ValidateAuthenticationStatus(Identity, ServiceName, ServiceUri); Response.StatusCode = response.Status; if (Identity.IsAuthenticated) { Response.Headers.Add(Constants.SsoResponseUserHeader, Identity.Username.ToString()); Response.Headers.Add(Constants.SsoResponseEmailHeader, Identity.Email.ToString()); } return(response); }