public async Task <bool> LoginAsync(string username, string password) { try { _act_client = Create <AccountClient>(); var apiResultOfLoginResult = await _act_client.LoginAsync(new LoginDto() { UserName = username, Password = password }); if (apiResultOfLoginResult.Code == (int)ApiCode.Success) { _result = apiResultOfLoginResult.Data; HttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {Token.Access_token}"); ApiResultOfUserInfoDto userInfoDto = await _act_client.MyInfoAsync(); MyInfo = userInfoDto.Data; } } catch (Exception ex) { throw new Exception("Login error ", ex); } return((bool)(_result?.SignIn.Succeeded)); }
public static async Task <Session> LoginAsync(this AccountClient client, string username, string password) { Session = (await client.LoginAsync(new LoginDto() { UserName = username, Password = password })).Data; var token = Session.Token; HttpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token.Access_token); ApiResultOfUserInfoDto userInfoDto = await client.MyInfoAsync(); MyInfo = userInfoDto.Data; return(Session); }
public static async Task <Session> LoginAsync(this AccountClient client, string username, string password) { Session = await client.LoginAsync(new LoginDto() { UserName = username, Password = password }); var token = Session.Token; HttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.Access_token}"); ApiResultOfUserInfoDto userInfoDto = await client.MyInfoAsync(); MyInfo = userInfoDto.Data; return(Session); }