Ejemplo n.º 1
0
 public RemoteCarRepository(string url, ITokenAuthenticator authenticator)
 {
     _client = new RestClient(url)
     {
         Authenticator = authenticator,
         Timeout       = 60000
     };
     _authenticator = authenticator;
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
        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;
 }
Ejemplo n.º 6
0
 public AuthenticatorHandler(ITokenAuthenticator tokenAuthenticator, ICredentialsAuthenticator credentialsAuthenticator)
 {
     _tokenAuthenticator       = tokenAuthenticator ?? throw new ArgumentNullException(nameof(tokenAuthenticator));
     _credentialsAuthenticator = credentialsAuthenticator ?? throw new ArgumentNullException(nameof(credentialsAuthenticator));
 }
Ejemplo n.º 7
0
 public TokenAuthenticationFilter(ITokenAuthenticator authenticator)
 {
     _authenticator = authenticator;
 }