public RemoteCarRepository(string url, ITokenAuthenticator authenticator) { _client = new RestClient(url) { Authenticator = authenticator, Timeout = 60000 }; _authenticator = authenticator; }
private void Init(ITokenAuthenticator authenticator) { ApiBaseUrl = "https://www.buxfer.com/api/"; _restClient = new RestClient(ApiBaseUrl); _restClient.AddHandler("application/x-javascript", () => new JsonDeserializer()); _restClient.PreAuthenticate = true; _restClient.Authenticator = authenticator; _restClient.FailOnDeserializationError = false; _authenticator = authenticator; }
public bool Authenticate(HttpActionContext actionContext, ITokenAuthenticator authenticator) { string token = string.Empty; try { token = actionContext.Request.Headers.GetValues(_authorizationHeaderKey).First(); } catch (Exception) { actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest) { Content = new StringContent("Missing Authorization Header (" + _authorizationHeaderKey + ")") }; return(false); } try { if (authenticator.Authenticate(token, actionContext)) { return(true); } else { throw new Exception(); } } catch (Exception e) { actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Unauthorized) { Content = new StringContent("Unauthorized User") }; return(false); } }
public bool Authenticate(HttpActionContext actionContext, ITokenAuthenticator authenticator) { string token = string.Empty; try { token = actionContext.Request.Headers.GetValues(_authorizationHeaderKey).First(); } catch (Exception) { actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest) { Content = new StringContent("Missing Authorization Header (" + _authorizationHeaderKey + ")") }; return false; } try { if (authenticator.Authenticate(token, actionContext)) { return true; } else { throw new Exception(); } } catch (Exception e) { actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Unauthorized) { Content = new StringContent("Unauthorized User") }; return false; } }
public TokenAuthenticationFilter(ITokenAuthenticator authenticator) { _authenticator = authenticator; }
public AuthenticatorHandler(ITokenAuthenticator tokenAuthenticator, ICredentialsAuthenticator credentialsAuthenticator) { _tokenAuthenticator = tokenAuthenticator ?? throw new ArgumentNullException(nameof(tokenAuthenticator)); _credentialsAuthenticator = credentialsAuthenticator ?? throw new ArgumentNullException(nameof(credentialsAuthenticator)); }
public TokenAuthenticationFilter(ITokenAuthenticator authenticator) { _authenticator = authenticator; }