コード例 #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;
 }
コード例 #2
0
 static JwtHelper()
 {
     jwtAlgorithm  = new HMACSHA256Algorithm();
     base64Encrpty = new JwtBase64UrlEncoder();
     serializer    = new JsonNetSerializer();
     provider      = new UtcDateTimeProvider();
 }
コード例 #3
0
 public TokenIssuer()
 {
     _algorithm     = new HMACSHA256Algorithm();
     _serializer    = new JsonNetSerializer();
     _base64Encoder = new JwtBase64UrlEncoder();
     _jwtEncoder    = new JwtEncoder(_algorithm, _serializer, _base64Encoder);
 }
コード例 #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;
 }
コード例 #5
0
ファイル: TokenMaker.cs プロジェクト: Ruannilton/Half-Pugg
 public TokenMaker()
 {
     algorithm  = new HMACSHA256Algorithm();
     serializer = new JsonNetSerializer();
     urlEncoder = new JwtBase64UrlEncoder();
     encoder    = new JwtEncoder(algorithm, serializer, urlEncoder);
 }
コード例 #6
0
 static JwtHelper()
 {
     _provider   = new UtcDateTimeProvider();
     _algorithm  = new HMACSHA256Algorithm();
     _serializer = new JsonNetSerializer();
     _urlEncoder = new JwtBase64UrlEncoder();
 }
コード例 #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);
 }
コード例 #8
0
ファイル: Token.cs プロジェクト: ferrarienz0/branch
 public Token(Dictionary <string, object> Payload)
 {
     this.Payload        = Payload;
     EncriptionAlgorithm = new HMACSHA256Algorithm();
     JSONSerializer      = new JsonNetSerializer();
     URLEncoder          = new JwtBase64UrlEncoder();
     JWTEncoder          = new JwtEncoder(EncriptionAlgorithm, JSONSerializer, URLEncoder);
 }
コード例 #9
0
 static SecurityManager()
 {
     _algorithm  = new HMACSHA256Algorithm();
     _serializer = new JsonNetSerializer();
     _urlEncoder = new JwtBase64UrlEncoder();
     _provider   = new UtcDateTimeProvider();
     _validator  = new JwtValidator(_serializer, _provider);
 }
コード例 #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);
 }
コード例 #11
0
ファイル: TokenMaker.cs プロジェクト: Ruannilton/Half-Pugg
        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);
        }
コード例 #12
0
ファイル: JwtImpl.cs プロジェクト: gitWanggg/XMService
        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);
        }
コード例 #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;
 }
コード例 #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);
 }
コード例 #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);
 }
コード例 #16
0
ファイル: JWT_Provider.cs プロジェクト: gauravi-lad/Spice
        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);
        }
コード例 #17
0
ファイル: JWT_Provider.cs プロジェクト: gauravi-lad/Spice
        public void Dispose()
        {
            _encoder = null;
            _decoder = null;

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

            _provider  = null;
            _validator = null;
        }
コード例 #18
0
ファイル: OnStarClient.cs プロジェクト: BrendanGrant/NOnStar
        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);
        }
コード例 #19
0
ファイル: JWTTools.cs プロジェクト: A0000000000/Shop
        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);
        }
コード例 #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);
                }
        }
コード例 #21
0
 public JwtFactory()
 {
     _algorithm  = new HMACSHA256Algorithm();
     _serializer = new JsonNetSerializer();
     _urlEncoder = new JwtBase64UrlEncoder();
 }
コード例 #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));
 }
コード例 #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())
 {
 }
コード例 #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);
 }
コード例 #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));
 }
コード例 #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))
 {
 }
コード例 #27
0
ファイル: JwtEncoder.cs プロジェクト: wangchengqun/jwt
 /// <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;
 }
コード例 #28
0
ファイル: JwtDecoder.cs プロジェクト: bch007/jwt
 /// <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;
 }