Beispiel #1
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)
 {
     _jsonSerializer = jsonSerializer;
     _jwtValidator   = jwtValidator;
     _urlEncoder     = urlEncoder;
 }
 static JwtHelper()
 {
     jwtAlgorithm  = new HMACSHA256Algorithm();
     base64Encrpty = new JwtBase64UrlEncoder();
     serializer    = new JsonNetSerializer();
     provider      = new UtcDateTimeProvider();
 }
Beispiel #3
0
 public TokenIssuer()
 {
     _algorithm     = new HMACSHA256Algorithm();
     _serializer    = new JsonNetSerializer();
     _base64Encoder = new JwtBase64UrlEncoder();
     _jwtEncoder    = new JwtEncoder(_algorithm, _serializer, _base64Encoder);
 }
Beispiel #4
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>
 public JwtDecoder(IJsonSerializer jsonSerializer, IJwtValidator jwtValidator, IBase64UrlEncoder urlEncoder, IAlgorithmFactory algFactory)
 {
     _jsonSerializer = jsonSerializer;
     _jwtValidator   = jwtValidator;
     _urlEncoder     = urlEncoder;
     _algFactory     = algFactory;
 }
Beispiel #5
0
 public TokenMaker()
 {
     algorithm  = new HMACSHA256Algorithm();
     serializer = new JsonNetSerializer();
     urlEncoder = new JwtBase64UrlEncoder();
     encoder    = new JwtEncoder(algorithm, serializer, urlEncoder);
 }
 static JwtHelper()
 {
     _provider   = new UtcDateTimeProvider();
     _algorithm  = new HMACSHA256Algorithm();
     _serializer = new JsonNetSerializer();
     _urlEncoder = new JwtBase64UrlEncoder();
 }
Beispiel #7
0
 public JwtManager(IJwtAlgorithm algorithm      = null, IJsonSerializer serializer = null,
                   IBase64UrlEncoder urlEncoder = null, string secret              = null)
 {
     _builder = new JwtBuilder().WithAlgorithm(algorithm ?? new HMACSHA256Algorithm())
                .WithSerializer(serializer ?? new JsonNetSerializer())
                .WithUrlEncoder(urlEncoder ?? new JwtBase64UrlEncoder())
                .WithSecret(secret ?? Secret);
 }
Beispiel #8
0
 public Token(Dictionary <string, object> Payload)
 {
     this.Payload        = Payload;
     EncriptionAlgorithm = new HMACSHA256Algorithm();
     JSONSerializer      = new JsonNetSerializer();
     URLEncoder          = new JwtBase64UrlEncoder();
     JWTEncoder          = new JwtEncoder(EncriptionAlgorithm, JSONSerializer, URLEncoder);
 }
Beispiel #9
0
 static SecurityManager()
 {
     _algorithm  = new HMACSHA256Algorithm();
     _serializer = new JsonNetSerializer();
     _urlEncoder = new JwtBase64UrlEncoder();
     _provider   = new UtcDateTimeProvider();
     _validator  = new JwtValidator(_serializer, _provider);
 }
Beispiel #10
0
 public TokenIssuer()
 {
     // JWT specific initialization.
     // https://github.com/jwt-dotnet/jwt
     _algorithm     = new HMACSHA256Algorithm();
     _serializer    = new JsonNetSerializer();
     _base64Encoder = new JwtBase64UrlEncoder();
     _jwtEncoder    = new JwtEncoder(_algorithm, _serializer, _base64Encoder);
 }
Beispiel #11
0
        public TokenValidation()
        {
            secret = TokenMaker.secret;

            serializer = new JsonNetSerializer();
            timeNet    = new UtcDateTimeProvider();
            validator  = new JwtValidator(serializer, timeNet);
            urlEncoder = new JwtBase64UrlEncoder();
            decoder    = new JwtDecoder(serializer, validator, urlEncoder);
        }
Beispiel #12
0
        void init()
        {
            urlEncoder = new JwtBase64UrlEncoder();
            serializer = new JsonNetSerializer();
            algorithm  = new HMACSHA256Algorithm();
            encoder    = new JwtEncoder(algorithm, serializer, urlEncoder);

            provider  = new UtcDateTimeProvider();
            validator = new JwtValidator(serializer, provider);
            decoder   = new JwtDecoder(serializer, validator, urlEncoder);
        }
Beispiel #13
0
 public TokenValidationService(IOptions <SecretKeys> secretKeys, ILogger <TokenValidationService> logger)
 {
     _algorithm  = new HMACSHA256Algorithm();
     _serializer = new JsonNetSerializer();
     _provider   = new UtcDateTimeProvider();
     _urlEncoder = new JwtBase64UrlEncoder();
     _validator  = new JwtValidator(_serializer, _provider);
     _decoder    = new JwtDecoder(_serializer, _validator, _urlEncoder, _algorithm);
     _secretKeys = secretKeys;
     _logger     = logger;
 }
Beispiel #14
0
 public JwtObjectEncoder(JwtSecretOptions jwtSecretOptions)
 {
     secret     = jwtSecretOptions.Secret;
     algorithm  = new HMACSHA256Algorithm();
     serializer = new JsonNetSerializer();
     urlEncoder = new JwtBase64UrlEncoder();
     provider   = new UtcDateTimeProvider();
     validator  = new JwtValidator(serializer, provider);
     encoder    = new JwtEncoder(algorithm, serializer, urlEncoder);
     decoder    = new JwtDecoder(serializer, validator, urlEncoder);
 }
Beispiel #15
0
 public JWTHelper()
 {
     //非fluent写法
     this._jsonSerializer   = new JsonNetSerializer();
     this._dateTimeProvider = new UtcDateTimeProvider();
     this._jwtValidator     = new JwtValidator(_jsonSerializer, _dateTimeProvider);
     this._base64UrlEncoder = new JwtBase64UrlEncoder();
     this._jwtAlgorithm     = new HMACSHA256Algorithm();
     this._jwtDecoder       = new JwtDecoder(_jsonSerializer, _jwtValidator, _base64UrlEncoder);
     this._jwtEncoder       = new JwtEncoder(_jwtAlgorithm, _jsonSerializer, _base64UrlEncoder);
 }
Beispiel #16
0
        public JWT_Provider()
        {
            _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);
        }
Beispiel #17
0
        public void Dispose()
        {
            _encoder = null;
            _decoder = null;

            _algorithm  = null;
            _serializer = null;
            _urlEncoder = null;

            _provider  = null;
            _validator = null;
        }
Beispiel #18
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);
        }
Beispiel #19
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);
        }
Beispiel #20
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);
                }
        }
 public JwtFactory()
 {
     _algorithm  = new HMACSHA256Algorithm();
     _serializer = new JsonNetSerializer();
     _urlEncoder = new JwtBase64UrlEncoder();
 }
Beispiel #22
0
 /// <summary>
 /// Creates an instance of <see cref="JwtDecoder" />
 /// </summary>
 /// <remarks>
 /// This overload supplies no <see cref="IJwtValidator" /> and no <see cref="IAlgorithmFactory" /> so the resulting decoder cannot be used for signature validation.
 /// </remarks>
 /// <param name="jsonSerializer">The Json Serializer</param>
 /// <param name="urlEncoder">The Base64 URL Encoder</param>
 /// <exception cref="ArgumentNullException" />
 public JwtDecoder(IJsonSerializer jsonSerializer, IBase64UrlEncoder urlEncoder)
 {
     _jsonSerializer = jsonSerializer ?? throw new ArgumentNullException(nameof(jsonSerializer));
     _urlEncoder     = urlEncoder ?? throw new ArgumentNullException(nameof(urlEncoder));
 }
Beispiel #23
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())
 {
 }
Beispiel #24
0
 /// <summary>
 /// Sets custom URL encoder.
 /// </summary>
 /// <remarks>
 /// If not set then default <see cref="JwtBase64UrlEncoder" /> will be used.
 /// </remarks>
 /// <returns>Current builder instance</returns>
 public JwtBuilder WithUrlEncoder(IBase64UrlEncoder urlEncoder)
 {
     _urlEncoder = urlEncoder;
     return(this);
 }
Beispiel #25
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));
 }
Beispiel #26
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))
 {
 }
Beispiel #27
0
 /// <summary>
 /// Creates an instance of <see cref="JwtEncoder" />
 /// </summary>
 /// <param name="jsonSerializer">The Json Serializer</param>
 /// <param name="algorithm">The Jwt Algorithm</param>
 /// <param name="urlEncoder">The Base64 URL Encoder</param>
 public JwtEncoder(IJwtAlgorithm algorithm, IJsonSerializer jsonSerializer, IBase64UrlEncoder urlEncoder)
 {
     _algorithm      = algorithm;
     _jsonSerializer = jsonSerializer;
     _urlEncoder     = urlEncoder;
 }
Beispiel #28
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;
 }