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 MicroTokenMintingService(IConfiguration configuration,
                                        DiscoverCacheContainerFactory discoverCacheContainerFactory)
        {
            _configuration = configuration;
            _discoverCacheContainerFactory = discoverCacheContainerFactory;
            var scheme = _configuration["microTokenMintingService:scheme"];

            _discoveryContainer = _discoverCacheContainerFactory.Get(_configuration["microTokenMintingService:scheme"]);

            _clientId     = _configuration["microTokenMintingService:clientId"];
            _clientSecret = _configuration["microTokenMintingService:clientSecret"];
        }
Beispiel #3
0
        public async Task <IViewComponentResult> InvokeAsync(string id)
        {
            string sourceId = id;

            if (string.IsNullOrWhiteSpace(sourceId))
            {
                sourceId = _discoverCacheContainerFactory.GetAll().Keys.FirstOrDefault();
            }

            var discoveryResponse = await _discoverCacheContainerFactory.Get(sourceId).DiscoveryCache.GetAsync();

            var model = new IdentitySourceViewComponentModel()
            {
                SchemeId          = sourceId,
                DiscoveryResponse = discoveryResponse
            };

            return(View(model));
        }