/// <summary> /// Retrieves <see cref="ApplicationUser"/> from DB and perform password check for basic login. /// </summary> /// <returns><see cref="BasicAuthenticationResult"/></returns> public async Task <BasicAuthenticationResult> Authenticate(EncryptedBasicLoginModel model) { var user = await _healthyGamerPortalDbContext.ApplicationUsers.FirstOrDefaultAsync( X => X.Email == Rfc7905.DecryptText(model.Email.Length, model.Email.Text)); // check if user exists if (user == null) { return(null); } // check if password is correct if (!VerifyPasswordHash(Convert.FromBase64String(user.Salt), Encoding.UTF8.GetBytes(Rfc7905.DecryptText(model.Password.Length, model.Password.Text)), Convert.FromBase64String(user.Password))) { return(null); } //Retrieve roles from DB BasicAuthenticationResult result = new BasicAuthenticationResult { Name = user.Email, Roles = new string[] { "Sad", "NotSad" } }; // authentication successful return(result); }
private async Task PopulateUserIdentity(BasicAuthenticationResult response) { var customClaims = await GetUserClaims(response.Name); // has to be retrieved from BasicAuthenticationResult in future var webToken = await GenerateWebToken(customClaims); var userIdentity = await GetIdentity(response.Name); await PerformSignIn(new GenericPrincipal(userIdentity, response.Roles), webToken.ToString()); }