/// <inheritdoc/> public virtual async Task <AuthenticationResult> ValidateAuthenticationCredentials( IConnection connection, IAuthenticationCredentials request) { var handlers = this.AuthenticationCredentialsValidationRequiredEventHandler; if (handlers != null) { var tasks = handlers.GetInvocationList() .Cast <AsyncEventHandler <AuthenticationCredentialsValidationEventArgs> >() .Select(h => { AuthenticationCredentialsValidationEventArgs args = new AuthenticationCredentialsValidationEventArgs(request); return(new { Args = args, Task = h(this, args) }); }); await Task.WhenAll(tasks.Select(t => t.Task).ToArray()).ConfigureAwait(false); AuthenticationResult?failureResult = tasks.Select(t => t.Args.AuthenticationResult) .Where(r => r != AuthenticationResult.Success) .FirstOrDefault(); return(failureResult ?? AuthenticationResult.Success); } return(AuthenticationResult.Failure); }
public virtual AuthenticationResult ValidateAuthenticationCredentials(IConnection connection, IAuthenticationCredentials request) { if (AuthenticationCredentialsValidationRequired != null) { AuthenticationCredentialsValidationRequired(this, new AuthenticationCredentialsValidationEventArgs(request)); } return(AuthenticationResult.Failure); }
public ISimpleTokenResult Authenticate(IAuthenticationCredentials credentials) { var client = new RestClient(GatewayUrl); var request = new RestRequest(Method.POST); request.AddParameter("username", credentials.Username); request.AddParameter("password", credentials.Password); var response = client.Execute <SimpleTokenResult>(request); return(response.Data); }
/** * Returns an Authentication string used for accessing Magento APIs * * @param AuthenticationCredentialsResource A model containing authentication credentials * @return string A string representing a token used for accessing Magento APIs */ public string Authenticate(IAuthenticationCredentials credentials) { var client = new RestClient(_authUrl); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddJsonBody(credentials); var response = client.Execute(request); //Ensure we get the right code CheckStatusCode(response.StatusCode); AuthToken = JsonConvert.DeserializeObject <string>(response.Content); return(AuthToken); }
private async Task <IAuthenticationCredentials> GetCredentialsWithRetry(int retryCount) { for (int i = 0; i < retryCount + 1; i++) { if (FatalError) { throw new AuthException(); } var currentAuth = _currentAuthenticationCredentials; if (currentAuth?.IsAlive() == true) { return(currentAuth); } await CredantialsRequestLock.WaitAsync(); try { if (FatalError) { throw new AuthException(); } if (_currentAuthenticationCredentials?.IsAlive() != true) { var result = await RequestCredentials(); if (result != null) { _currentAuthenticationCredentials = result; } else { FatalError = true; } } } finally { CredantialsRequestLock.Release(); } } throw new TimeoutException(); }
/** * Returns an Authentication string used for accessing EA APIs * * @param AuthenticationCredentials A model containing authentication credentials * @return access_token A string representing a token used for accessing EA APIs */ public string Authenticate(IAuthenticationCredentials credentials) { var client = new RestClient(_authUrl); var request = new RestRequest("token", Method.POST) .AddParameter("grant_type", credentials.grant_type) .AddParameter("username", credentials.username) .AddParameter("password", credentials.password) .AddParameter("client_id", credentials.client_id) .AddParameter("client_secret", credentials.client_secret); request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); var response = client.Execute(request); //Ensure we get the right code CheckStatusCode(response.StatusCode); AuthToken = JsonConvert.DeserializeObject <AuthTokenResource>(response.Content).access_token; return(AuthToken); }
public AuthenticationCredentialsValidationEventArgs(IAuthenticationCredentials credentials) { Credentials = credentials; }
public Api(IAuthenticationCredentials credentials, IResponseCache cache) : this(credentials) { ResponseCache = cache; }
public Api(IAuthenticationCredentials credentials) : this() { Authentication = credentials; }
public Task <AuthenticationResult> ValidateAuthenticationCredentialsAsync(IConnection connection, IAuthenticationCredentials authenticationRequest) { return(Task.FromResult(AuthenticationResult.Success)); }
public AuthenticationResult ValidateAuthenticationCredentials(IConnection connection, IAuthenticationCredentials authenticationRequest) { return(AuthenticationResult.Success); }
public virtual AuthenticationResult ValidateAuthenticationCredentials(IConnection connection, IAuthenticationCredentials request) { if (AuthenticationCredentialsValidationRequired != null) { AuthenticationCredentialsValidationRequired(this, new AuthenticationCredentialsValidationEventArgs(request)); } return AuthenticationResult.Failure; }