示例#1
0
        protected async Task<TokenCacheInfo> RefreshToken(CustomTokenCache tokenCache, TokenCacheInfo cacheInfo)
        {
            if (!String.IsNullOrEmpty(cacheInfo.RefreshToken))
            {
                try
                {
                    return await GetAuthorizationResultByRefreshToken(tokenCache, cacheInfo);
                }
                catch (AdalServiceException ex)
                {
                    if (ex.Message.IndexOf("The provided access grant is expired or revoked") > 0)
                    {
                        AcquireTokens().Wait();
                        cacheInfo = GetToken(cacheInfo.TenantId).Result;
                        tokenCache.Clone(this.TokenStorage.GetCache());
                        return cacheInfo;
                    }

                    throw;
                }
            }
            else if (!String.IsNullOrEmpty(cacheInfo.AppId) && cacheInfo.AppKey == "_certificate_")
            {
                throw new InvalidOperationException("Unable to refresh expired token!  Try login with certificate again.");
            }
            else if (!String.IsNullOrEmpty(cacheInfo.AppId) && !String.IsNullOrEmpty(cacheInfo.AppKey))
            {
                return GetAuthorizationResultBySpn(tokenCache, cacheInfo.TenantId, cacheInfo.AppId, cacheInfo.AppKey, cacheInfo.Resource);
            }

            throw new NotImplementedException();
        }