Exemplo n.º 1
0
 public AccountController(
     ITokenService tokenService,
     IUserManager <WatchmanUser, Guid> userManager,
     IPersonalInformationService <PersonalInfo, Guid> personalInformationService,
     IJwtValidator jwtValidator
     )
 {
     this._tokenService = tokenService;
     this._userManager  = userManager;
     this._infoService  = personalInformationService;
     this._jwtValidator = jwtValidator;
 }
Exemplo n.º 2
0
        static JWTTools()
        {
            algorithm  = new HMACSHA256Algorithm();
            serializer = new JsonNetSerializer();
            urlEncoder = new JwtBase64UrlEncoder();

            encoder = new JwtEncoder(algorithm, serializer, urlEncoder);

            provider  = new UtcDateTimeProvider();
            validator = new JwtValidator(serializer, provider);
            decoder   = new JwtDecoder(serializer, validator, urlEncoder, algorithm);
        }
Exemplo n.º 3
0
        public OnStarClient(string username, string password, string pin)
        {
            this.username = username;
            this.password = password;
            this.pin      = pin;

            serializer = new JsonNetSerializer();
            provider   = new UtcDateTimeProvider();
            validator  = new JwtValidator(serializer, provider);
            urlEncoder = new JwtBase64UrlEncoder();
            decoder    = new JwtDecoder(serializer, validator, urlEncoder);
        }
Exemplo n.º 4
0
        public void InitializerPropertiesTest()
        {
            Mock <IJsonSerializer>   mSerializer   = new Mock <IJsonSerializer>();
            IJsonSerializer          serializer    = mSerializer.Object;
            Mock <IDateTimeProvider> mProvider     = new Mock <IDateTimeProvider>();
            IDateTimeProvider        provider      = mProvider.Object;
            Mock <IJwtValidator>     mValidator    = new Mock <IJwtValidator>();
            IJwtValidator            validator     = mValidator.Object;
            Mock <IBase64UrlEncoder> mUrlEncoder   = new Mock <IBase64UrlEncoder>();
            IBase64UrlEncoder        urlEncoder    = mUrlEncoder.Object;
            Mock <IJwtDecoder>       mDecoder      = new Mock <IJwtDecoder>();
            IJwtDecoder            decoder         = mDecoder.Object;
            Mock <IJwtAlgorithm>   mAlgorithm      = new Mock <IJwtAlgorithm>();
            IJwtAlgorithm          algorithm       = mAlgorithm.Object;
            Mock <IJwtEncoder>     mEncoder        = new Mock <IJwtEncoder>();
            IJwtEncoder            encoder         = mEncoder.Object;
            Mock <ILoggingService> mLoggingService = new Mock <ILoggingService>();
            ILoggingService        loggingService  = mLoggingService.Object;

            using (SecureString secret = _secret.ToSecureString())
                using (JwtServiceArgs args = new JwtServiceArgs(false, null, null)
                {
                    Secret = _secret,
                    SecureSecret = secret,
                    Serializer = serializer,
                    Provider = provider,
                    Validator = validator,
                    UrlEncoder = urlEncoder,
                    Decoder = decoder,
                    Algorithm = algorithm,
                    Encoder = encoder,
                    LoggingService = loggingService
                })
                {
                    Assert.Equal(_secret, args.Secret);
                    Assert.Equal(secret, args.SecureSecret);
                    Assert.Equal(_secret, args.SecureSecret.ToPlainText());
                    Assert.Equal(serializer, args.Serializer);
                    Assert.Equal(provider, args.Provider);
                    Assert.Equal(validator, args.Validator);
                    Assert.Equal(urlEncoder, args.UrlEncoder);
                    Assert.Equal(decoder, args.Decoder);
                    Assert.Equal(algorithm, args.Algorithm);
                    Assert.Equal(encoder, args.Encoder);
                    Assert.Equal(loggingService, args.LoggingService);
                }
        }
Exemplo n.º 5
0
 public AccountController(
     ILoginService <IdentityUser, Guid> loginService,
     IUserManager <IdentityUser, Guid> userManager,
     IRoleService <Guid> roleService,
     ILogger <AccountController> logger,
     IConfiguration configuration,
     IJwtGenerator jwtGenerator,
     IJwtValidator jwtValidator)
 {
     this._loginService  = loginService;
     this._userManager   = userManager;
     this._roleService   = roleService;
     this._logger        = logger;
     this._configuration = configuration;
     this._jwtGenerator  = jwtGenerator;
     this._jwtValidator  = jwtValidator;
 }
Exemplo n.º 6
0
        private void TryCreateValidator()
        {
            if (_validator is object)
            {
                return;
            }

            if (_serializer is null)
            {
                throw new InvalidOperationException($"Can't instantiate {nameof(JwtValidator)}. Call {nameof(WithSerializer)}.");
            }
            if (_dateTimeProvider is null)
            {
                throw new InvalidOperationException($"Can't instantiate {nameof(JwtValidator)}. Call {nameof(WithDateTimeProvider)}.");
            }

            _validator = new JwtValidator(_serializer, _dateTimeProvider);
        }
        /// <summary>
        /// Inicializa la instancia del tipo <see cref="RestSharp.RestClient"/> que se utilza para enviar las solicitudes al servicio Aspen.
        /// </summary>
        protected void InitializeClient()
        {
            this.JwtEncoder = new JwtEncoder(this.algorithm, ServiceLocator.Instance.JwtJsonSerializer, this.urlEncoder);
            this.validator  = new JwtValidator(ServiceLocator.Instance.JwtJsonSerializer, this.datetimeProvider);
            this.JwtDecoder = new JwtDecoder(ServiceLocator.Instance.JwtJsonSerializer, this.validator, this.urlEncoder, this.algorithm);
            this.RestClient = new RestClient(this.endpoint.ToString().TrimEnd('/'))
            {
                Timeout = (int)this.timeout.TotalMilliseconds
            };
            this.RestClient.UseSerializer(() => JsonNetSerializer.Default);

            IWebProxy webProxy = ServiceLocator.Instance.WebProxy;

            if (webProxy.GetType() != typeof(NullWebProxy))
            {
                this.RestClient.Proxy = ServiceLocator.Instance.WebProxy;
            }

            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                Formatting            = Formatting.Indented,
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            };
        }
Exemplo n.º 8
0
 /// <summary>
 /// Sets JWT validator.
 /// </summary>
 /// <remarks>
 /// Required to decode with verification.
 /// </remarks>
 /// <returns>Current builder instance</returns>
 public JwtBuilder WithValidator(IJwtValidator validator)
 {
     _validator = validator;
     return(this);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Creates an instance of <see cref="JwtDecoder" />
 /// </summary>
 /// <param name="jsonSerializer">The Json Serializer</param>
 /// <param name="jwtValidator">The Jwt validator</param>
 /// <param name="urlEncoder">The Base64 URL Encoder</param>
 /// <param name="algorithm">The Algorithm</param>
 public JwtDecoder(IJsonSerializer jsonSerializer, IJwtValidator jwtValidator, IBase64UrlEncoder urlEncoder, IJwtAlgorithm algorithm)
     : this(jsonSerializer, jwtValidator, urlEncoder, new DelegateAlgorithmFactory(algorithm))
 {
 }
Exemplo n.º 10
0
 public TokenParser(OidcSettings settings, IJwtValidator validator, ILogger <TokenParser> logger)
 {
     Settings  = settings;
     Validator = validator;
     Logger    = logger;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Creates an instance of <see cref="JwtDecoder" />.
 /// </summary>
 /// <param name="jsonSerializer">The Json Serializer.</param>
 /// <param name="jwtValidator">The Jwt validator.</param>
 /// <param name="urlEncoder">The Base64 URL Encoder.</param>
 public JwtDecoder(IJsonSerializer jsonSerializer, IJwtValidator jwtValidator, IBase64UrlEncoder urlEncoder)
     : this(jsonSerializer, jwtValidator, urlEncoder, _defaultAlgorithmFactory)
 {
 }
Exemplo n.º 12
0
 /// <summary>
 /// Creates an instance of <see cref="JwtDecoder" />
 /// </summary>
 /// <param name="jsonSerializer">The Json Serializer</param>
 /// <param name="jwtValidator">The Jwt validator</param>
 /// <param name="urlEncoder">The Base64 URL Encoder</param>
 /// <param name="algFactory">The Algorithm Factory</param>
 /// <exception cref="ArgumentNullException" />
 public JwtDecoder(IJsonSerializer jsonSerializer, IJwtValidator jwtValidator, IBase64UrlEncoder urlEncoder, IAlgorithmFactory algFactory)
     : this(jsonSerializer, urlEncoder)
 {
     _jwtValidator = jwtValidator ?? throw new ArgumentNullException(nameof(jwtValidator));
     _algFactory   = algFactory ?? throw new ArgumentNullException(nameof(algFactory));
 }
Exemplo n.º 13
0
 public AccountController(IDocumentSession session, IJwtValidator jwtValidator, IAccountant accountant)
 {
     _session = session;
     _jwtValidator = jwtValidator;
     _accountant = accountant;
 }
Exemplo n.º 14
0
 public TokenJwtBinder(string secret)
 {
     validator = new JwtValidator(serializer, provider);
     decoder   = new JwtDecoder(serializer, validator, urlEncoder);
     _secret   = secret;
 }
Exemplo n.º 15
0
 /// <summary>
 /// Creates an instance of <see cref="JwtDecoder" />.
 /// </summary>
 /// <param name="jsonSerializer">The Json Serializer.</param>
 /// <param name="jwtValidator">The Jwt validator.</param>
 /// <param name="urlEncoder">The Base64 URL Encoder.</param>
 public JwtDecoder(IJsonSerializer jsonSerializer, IJwtValidator jwtValidator, IBase64UrlEncoder urlEncoder)
     : this(jsonSerializer, jwtValidator, urlEncoder, new HMACSHAAlgorithmFactory())
 {
 }
Exemplo n.º 16
0
 /// <summary>
 /// Creates an instance of the decoder.
 /// </summary>
 /// <param name="jsonSerializer">The Json Serializer.</param>
 /// <param name="jwtValidator">The Jwt Validator.</param>
 /// <param name="urlEncoder">The Base64 URL Encoder.</param>
 public JwtDecoder(IJsonSerializer jsonSerializer, IJwtValidator jwtValidator, IBase64UrlEncoder urlEncoder)
 {
     _jsonSerializer = jsonSerializer;
     _jwtValidator   = jwtValidator;
     _urlEncoder     = urlEncoder;
 }
Exemplo n.º 17
0
 public JwtDecoder(IJsonSerializer jsonSerializer, IJwtValidator jwtValidator)
 {
     _jsonSerializer = jsonSerializer;
     _jwtValidator   = jwtValidator;
 }