Example #1
0
        public TokenManager(ITokenKeyStore tokenKeyStorage)
        {
            _tokenKeyStorage = tokenKeyStorage;

            secretKey   = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_tokenKeyStorage.SymmtricKey));
            credentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256Signature);
            handler     = new JwtSecurityTokenHandler();
            issuer      = _tokenKeyStorage.Issuer;
        }
Example #2
0
        public JwtTokenIssuer(IOptions <JwtIssuerOptions> issuerOptions, IEnumerable <ITokenKeyStore> keyStores, ILoggerFactory loggerFactory)
        {
            _issuerOptions = issuerOptions.Value;

            var tokenKeyStores = keyStores.ToList();

            _symmetricKeyStore = tokenKeyStores.FirstOrDefault(s => s.KeyType == KeyType.HSSymmetricKey);
            _privateKeyStore   = tokenKeyStores.FirstOrDefault(s => s.KeyType == KeyType.RsaPrivateKey);

            _logger = loggerFactory.CreateLogger("JwtTokenIssuer");
        }
Example #3
0
        // start file-change monitor to detect, when key is updated
        // Note! required to be a singleton
        public static Task StartMonitor(this ITokenKeyStore store, string path, string filter,
                                        CancellationToken cancellationToken, Action changeAction)
        => Task.Factory.StartNew(
            () =>
        {
            var watcher = new FileSystemWatcher
            {
                NotifyFilter = NotifyFilters.LastWrite,
                Path         = Path.GetDirectoryName(path),
                Filter       = filter
            };

            while (!cancellationToken.IsCancellationRequested)
            {
                var result = watcher.WaitForChanged(WatcherChangeTypes.Changed);
                if (result.ChangeType == WatcherChangeTypes.Changed)
                {
                    changeAction();
                }
            }
        }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default);
Example #4
0
 /// <summary>
 /// Sets the token key store ued by the tokenizer
 /// </summary>
 /// <param name="store"></param>
 /// <returns>A reference to the current <see cref="TokenizerConfigurator"/></returns>
 public TokenizerConfigurator WithKeyCache(ITokenKeyStore store)
 {
     this.tokenizer.keyStore = store;
     return(this);
 }
 /// <summary>
 /// Sets the token key store ued by the tokenizer
 /// </summary>
 /// <param name="store"></param>
 /// <returns>A reference to the current <see cref="TokenizerConfigurator"/></returns>
 public TokenizerConfigurator WithKeyCache(ITokenKeyStore store)
 {
     this.tokenizer.keyStore = store;
     return this;
 }