public async Task <bool> LoginAsync(LoginParamsType model)
        {
            var document = await _httpClient.GetDiscoveryDocumentAsync();

            var tokenResult = await _httpClient.RequestPasswordTokenAsync(new PasswordTokenRequest
            {
                Address  = document.TokenEndpoint,
                UserName = model.UserName,
                Password = model.Password,
                ClientId = _options.ProviderOptions.ClientId,
                Scope    = string.Join(" ", _options.ProviderOptions.DefaultScopes)
            });

            if (!tokenResult.IsError)
            {
                await _accessTokenService.SaveAccessToken(tokenResult);

                ((ApiAuthenticationStateProvider)_authenticationStateProvider).MarkUserAsAuthenticated(model.UserName);
                _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", tokenResult.AccessToken);

                return(true);
            }

            return(false);
        }
コード例 #2
0
ファイル: AccountService.cs プロジェクト: ebekker/conjure
 public Task LoginAsync(LoginParamsType model)
 {
     // todo: login logic
     return(Task.CompletedTask);
 }
コード例 #3
0
ファイル: AccountService.cs プロジェクト: y001j/IoTSharp
 public async Task <bool> LoginAsync(LoginParamsType model)
 {
     return(await _client.LoginAsync(model.UserName, model.Password));
 }