public AuthenticationResult SignIn(UserCredentials userCredentials, IAuthenticationHandler authenticationHandler) { var result = authenticationHandler.AuthenticateAsync(userCredentials).Result; _lastResult = result; OnAuthenticationChanged(); return(result); }
/// <summary> /// Signs the user in and registers the user for Push notifications. /// </summary> /// <param name="provider">The provider.</param> public async Task SignInAsync(MobileServiceAuthenticationProvider provider) { await _authenticationHandler.AuthenticateAsync(provider); var user = await GetCurrentUser(); AppEnvironment.Instance.CurrentUser = user; RegisterForNotifications(); }
public async Task <IActionResult> Authenticate([FromBody] AuthenticationRequest request) { _logger.LogInformation(JsonSerializer.Serialize(request)); try { AuthenticationResponse response = await _authHandler.AuthenticateAsync(request); _logger.LogInformation(JsonSerializer.Serialize(response)); return(Ok(response)); } catch (ArgumentException) { return(BadRequest(new { error = "invalid authentication request" })); } }
/// <summary> /// Signs the user in and registers the user for Push notifications. /// </summary> /// <param name="provider">The provider.</param> public async Task SignInAsync(MobileServiceAuthenticationProvider provider) { await _authenticationHandler.AuthenticateAsync(provider); _telemetryClient.TrackTrace("Signed in with Azure App Service"); var user = await GetCurrentUser(); AppEnvironment.Instance.CurrentUser = user; RegisterForNotifications(); }
public async Task RefereshAuthenticationAsync() { _httpClient.DefaultRequestHeaders.Remove("Authorization"); if (!string.IsNullOrEmpty(_tokenHolder.RefreshToken.ToInsecureString())) { try { _logger.LogInformation($"Getting a new access token using refresh token"); var scopes = _tokenHolder.Scopes; var tokenInfoResponse = await RefreshOpenIdTokenAsync(_tokenHolder.RefreshToken, scopes); _logger.LogInformation($"Obtained a new access token using refresh token"); var tokens = new TokenHolder(tokenInfoResponse, scopes); SetTokens(tokens); // fire the 'token updated' event TokenUpdated?.Invoke(tokens); return; } catch (Exception ex) { _logger.LogInformation(ex, "Could not refersh access token using the refresh_token"); } } // authenticate again (using credentials or whatever the handler can do for us) if (_authHandler != null) { _logger.LogInformation($"Getting a new access token using {_authHandler.GetType()}"); var tokens = await _authHandler.AuthenticateAsync(); _logger.LogInformation($"Obtained a new access token using {_authHandler.GetType()}"); SetTokens(tokens); // fire the 'token updated' event TokenUpdated?.Invoke(tokens); } else { throw new AuthenticationException( "Unable to refresh access token and there is no way to re-authenticate."); } }
public Task AuthenticateAsync(AuthenticateContext context) { return(_handler.AuthenticateAsync(context)); }