private async Task <LoginResult> GetLoginResultAsync(string username, string password, string tenancyName) { var loginResult = await _loginManager.LoginAsync(username, password, tenancyName); switch (loginResult.Result) { case LoginResultType.Success: return(loginResult); default: throw _loginResultTypeHelper.CreateExceptionForFailedLoginAttempt(loginResult.Result, username, tenancyName); } }
private LoginResult <User> GetLoginResult(string usernameOrEmailAddress, string password) { var loginResult = _loginManager.Login(usernameOrEmailAddress, password); switch (loginResult.Result) { case AbpLoginResultType.Success: return(loginResult); default: throw _loginResultTypeHelper.CreateExceptionForFailedLoginAttempt(loginResult.Result, usernameOrEmailAddress); } }
public async Task <ExternalAuthenticateResultModel> ExternalAuthenticate(ExternalAuthenticateModel model) { //var externalUser = await GetExternalUserInfo(model); var loginResult = await _loginManager.LoginAsync(new UserLoginInfo(model.AuthProvider, model.ProviderKey, model.AuthProvider)); switch (loginResult.Result) { case LoginResultType.Success: { var accessToken = CreateAccessToken(CreateJwtClaims(loginResult.Identity)); var permissions = await UserManager.GetGrantedPermissionsAsync(loginResult.User); var result = new ExternalAuthenticateResultModel { AccessToken = accessToken, EncryptedAccessToken = GetEncrpyedAccessToken(accessToken), ExpireInSeconds = (int)_configuration.Expiration.TotalSeconds, GrantedPermissions = permissions.Select(o => o.Name) }; //如果是电脑浏览器登录,则需要记录当前token,用于限制同一时间单账号登录 if (model.ClientInfo == "Browser") { loginResult.User.SetData("currentToken", result.EncryptedAccessToken); } await UserManager.UpdateAsync(loginResult.User); //HttpContext.Session.Set("LoginInfo", loginResult.User.Id); return(result); } //case LoginResultType.UnknownExternalLogin: // { // var newUser = await RegisterExternalUserAsync(externalUser); // if (!newUser.IsActive) // { // return new ExternalAuthenticateResultModel // { // WaitingForActivation = true // }; // } // //Try to login again with newly registered user! // loginResult = await _loginManager.LoginAsync(new UserLoginInfo(model.AuthProvider, model.ProviderKey, model.AuthProvider), GetTenancyNameOrNull()); // if (loginResult.Result != LoginResultType.Success) // { // throw _loginResultTypeHelper.CreateExceptionForFailedLoginAttempt( // loginResult.Result, // model.ProviderKey, // GetTenancyNameOrNull() // ); // } // var accessToken = CreateAccessToken(CreateJwtClaims(loginResult.Identity)); // return new ExternalAuthenticateResultModel // { // AccessToken = accessToken, // EncryptedAccessToken = GetEncrpyedAccessToken(accessToken), // ExpireInSeconds = (int)_configuration.Expiration.TotalSeconds // }; // } default: { throw _loginResultTypeHelper.CreateExceptionForFailedLoginAttempt( loginResult.Result, model.ProviderKey, GetTenancyNameOrNull() ); } } }