Пример #1
0
        protected virtual async Task <string> GetTokenEndpoint(IdentityClientConfiguration configuration)
        {
            //TODO: Can use (configuration.Authority + /connect/token) directly?

            var tokenEndpointUrlCacheKey   = CalculateDiscoveryDocumentCacheKey(configuration);
            var discoveryDocumentCacheItem = await DiscoveryDocumentCache.GetAsync(tokenEndpointUrlCacheKey);

            if (discoveryDocumentCacheItem == null)
            {
                var discoveryResponse = await GetDiscoveryResponse(configuration);

                if (discoveryResponse.IsError)
                {
                    throw new AbpException($"Could not retrieve the OpenId Connect discovery document! " +
                                           $"ErrorType: {discoveryResponse.ErrorType}. Error: {discoveryResponse.Error}");
                }

                discoveryDocumentCacheItem = new IdentityModelDiscoveryDocumentCacheItem(discoveryResponse.TokenEndpoint);
                await DiscoveryDocumentCache.SetAsync(tokenEndpointUrlCacheKey, discoveryDocumentCacheItem,
                                                      new DistributedCacheEntryOptions
                {
                    AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(configuration.CacheAbsoluteExpiration)
                });
            }

            return(discoveryDocumentCacheItem.TokenEndpoint);
        }
Пример #2
0
 protected virtual string CalculateDiscoveryDocumentCacheKey(IdentityClientConfiguration configuration)
 {
     return(IdentityModelDiscoveryDocumentCacheItem.CalculateCacheKey(configuration));
 }