public static void ClearAccessTokens(this ITokenCacheAccessor accessor)
 {
     lock (_lock)
     {
         foreach (var item in accessor.GetAllAccessTokens())
         {
             accessor.DeleteAccessToken(item.GetKey());
         }
     }
 }
Example #2
0
        private void DeleteAccessTokensWithIntersectingScopes(
            AuthenticationRequestParameters requestParams,
            IEnumerable <string> environmentAliases,
            string tenantId,
            HashSet <string> scopeSet,
            string homeAccountId,
            string tokenType)
        {
            // delete all cache entries with intersecting scopes.
            // this should not happen but we have this as a safe guard
            // against multiple matches.
            requestParams.RequestContext.Logger.Info("Looking for scopes for the authority in the cache which intersect with " +
                                                     requestParams.Scope.AsSingleString());
            IList <MsalAccessTokenCacheItem> accessTokenItemList = new List <MsalAccessTokenCacheItem>();

            foreach (var accessToken in _accessor.GetAllAccessTokens())
            {
                if (accessToken.ClientId.Equals(ClientId, StringComparison.OrdinalIgnoreCase) &&
                    environmentAliases.Contains(accessToken.Environment) &&
                    string.Equals(accessToken.TokenType ?? "", tokenType ?? "", StringComparison.OrdinalIgnoreCase) &&
                    (accessToken.IsAdfs || accessToken.TenantId.Equals(tenantId, StringComparison.OrdinalIgnoreCase)) &&
                    accessToken.ScopeSet.Overlaps(scopeSet))
                {
                    requestParams.RequestContext.Logger.Verbose("Intersecting scopes found");
                    accessTokenItemList.Add(accessToken);
                }
            }

            requestParams.RequestContext.Logger.Info("Intersecting scope entries count - " + accessTokenItemList.Count);

            if (!requestParams.IsClientCredentialRequest)
            {
                // filter by identifier of the user instead
                accessTokenItemList =
                    accessTokenItemList.Where(
                        item => item.HomeAccountId.Equals(homeAccountId, StringComparison.OrdinalIgnoreCase))
                    .ToList();
                requestParams.RequestContext.Logger.Info("Matching entries after filtering by user - " + accessTokenItemList.Count);
            }

            foreach (var cacheItem in accessTokenItemList)
            {
                _accessor.DeleteAccessToken(cacheItem.GetKey());
            }
        }
Example #3
0
 /// <inheritdoc />
 public void DeleteAccessToken(MsalAccessTokenCacheKey cacheKey)
 {
     _tokenCacheAccessor.DeleteAccessToken(cacheKey);
 }