Beispiel #1
0
        public virtual async Task <ClaimsPrincipal> ValidateTokenAsync(TokenDescriptor tokenDescriptor)
        {
            if (tokenDescriptor.TokenScheme != TokenScheme)
            {
                throw new ArgumentException($"{nameof(tokenDescriptor.TokenScheme)} must be {TokenScheme} to use this validator");
            }
            var discoveryContainer = _discoverCacheContainerFactory.Get(tokenDescriptor.TokenScheme);

            if (discoveryContainer == null)
            {
                throw new ArgumentException($"The OIDC AuthorityKey:{nameof(tokenDescriptor.TokenScheme)} is not supported");
            }
            var providerValidator = new ProviderValidator(discoveryContainer, _memoryCache);

            try
            {
                var principal = await providerValidator.ValidateToken(tokenDescriptor.Token,
                                                                      new TokenValidationParameters()
                {
                    ValidateAudience = false
                });

                return(principal);
            }
            catch (Exception e)
            {
                throw new Exception("Invalid Binding Token", e);
            }
        }
        public async Task <ClaimsPrincipal> ValidateTokenAsync(TokenDescriptor tokenDescriptor)
        {
            Guard.ArgumentNotNull(nameof(tokenDescriptor), tokenDescriptor);
            Guard.ArgumentNotNull(nameof(tokenDescriptor.TokenScheme), tokenDescriptor.TokenScheme);
            Guard.ArgumentNotNull(nameof(tokenDescriptor.Token), tokenDescriptor.Token);
            Guard.ArgumentValid(_mapValidators.ContainsKey(tokenDescriptor.TokenScheme),
                                nameof(tokenDescriptor.TokenScheme),
                                $"{tokenDescriptor.TokenScheme} is not supported!");

            var validator = _mapValidators[tokenDescriptor.TokenScheme];

            return(await validator.ValidateTokenAsync(tokenDescriptor));
        }