public TokenIssueEventHandlerSetup(TEventHandler eventHandler)
        {
            if (eventHandler == null)
            {
                throw new ArgumentNullException(nameof(eventHandler));
            }

            _eventHandler = eventHandler;
        }
        public TokensIssuingMiddleware(RequestDelegate next, IUserClaimsProvider userClaimsProvider, IOptions <TokensIssuingOptions> options)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }
            if (userClaimsProvider == null)
            {
                throw new ArgumentNullException(nameof(userClaimsProvider));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (string.IsNullOrWhiteSpace(options.Value.GetEndpotint))
            {
                throw new ArgumentNullException(nameof(options.Value.GetEndpotint));
            }
            if (string.IsNullOrWhiteSpace(options.Value.SigningAlgorithmName))
            {
                throw new ArgumentNullException(nameof(options.Value.SigningAlgorithmName));
            }
            if (options.Value.SigningKey == null)
            {
                throw new ArgumentNullException(nameof(options.Value.SigningKey));
            }

            _next = next;
            _userClaimsProvider     = userClaimsProvider;
            _tokenHandler           = new JwtSecurityTokenHandler();
            _tokenIssueEventHandler = options.Value.TokenIssueEventHandler;
            _getEndpointPath        = new PathString(options.Value.GetEndpotint);
            _signingCredentials     = new SigningCredentials(options.Value.SigningKey, options.Value.SigningAlgorithmName);
            _lifetime = options.Value.Lifetime;

            _jsonSerializerSettings = new JsonSerializerSettings().UseDefaultSettings();
        }
 public void SetTokenIssueEventHandlerFailTest(TokensIssuingOptions options, ITokenIssueEventHandler eventHandler)
 {
     Assert.Throws <ArgumentNullException>(() => options.WithTokenIssueEventHandler(eventHandler));
 }
        public static TokensIssuingOptions WithTokenIssueEventHandler(this TokensIssuingOptions options, ITokenIssueEventHandler eventHandler)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (eventHandler == null)
            {
                throw new ArgumentNullException(nameof(eventHandler));
            }

            options.TokenIssueEventHandler = eventHandler;
            return(options);
        }