예제 #1
0
        protected async Task <TokenCacheInfo> GetAuthorizationResultBySpn(CustomTokenCache tokenCache, string tenantId, string appId, X509Certificate2 certificate, string resource)
        {
            TokenCacheInfo found;

            if (tokenCache.TryGetValue(tenantId, resource, out found))
            {
                return(found);
            }

            var helper        = new JwtHelper();
            var tokenEndpoint = string.Format("{0}/{1}/oauth2/token", Constants.AADLoginUrls[(int)this.AzureEnvironments], tenantId);
            var token         = await helper.AcquireTokenByX509(tenantId, appId, certificate, resource, tokenEndpoint);

            var cacheInfo = new TokenCacheInfo(tenantId, appId, "_certificate_", resource, token);

            tokenCache.Add(cacheInfo);
            return(cacheInfo);
        }