private MsalAccessTokenCacheItem(
            string scopes,
            DateTimeOffset cachedAt,
            DateTimeOffset expiresOn,
            DateTimeOffset extendedExpiresOn,
            DateTimeOffset?refreshOn,
            string tenantId,
            string keyId,
            string tokenType)
        {
            CredentialType = StorageJsonValues.CredentialTypeAccessToken;

            ScopeString = scopes;
            ScopeSet    = ScopeHelper.ConvertStringToScopeSet(ScopeString);

            ExpiresOn         = expiresOn;
            ExtendedExpiresOn = extendedExpiresOn;
            RefreshOn         = refreshOn;

            TenantId  = tenantId ?? "";
            KeyId     = keyId;
            TokenType = tokenType;

            CachedAt = cachedAt;
        }
示例#2
0
        public void ScopeHelperPerf()
        {
            ISet <string> scopeSet = null;

            using (new PerformanceValidator(100, "Convert scope string to set"))
            {
                // about 500ms for 5000 iterations -> down to 160ms after replacing SortedSet with HashSet
                for (int i = 0; i < 1000; i++)
                {
                    scopeSet = ScopeHelper.ConvertStringToScopeSet(LotsOfScopes);
                }
            }
            bool contains = true;

            using (new PerformanceValidator(100, "Scope contains"))
            {
                // about 150ms for 10000 iterations -> down to 5ms after replacing SortedSet with HashSet
                for (int i = 0; i < 10000; i++)
                {
                    contains = ScopeHelper.ScopeContains(
                        scopeSet,
                        new[] { "Tasks.ReadWrite", "Agreement.ReadWrite.All", "bogus" });
                }
            }
            Assert.IsFalse(contains);
        }
示例#3
0
        public static void AreScopesEqual(string scopesExpected, string scopesActual)
        {
            var expectedScopes = ScopeHelper.ConvertStringToScopeSet(scopesExpected);
            var actualScopes   = ScopeHelper.ConvertStringToScopeSet(scopesActual);

            // can't use Assert.AreEqual on HashSet, so we'll compare by hand.
            Assert.AreEqual(expectedScopes.Count, actualScopes.Count);
            foreach (string expectedScope in expectedScopes)
            {
                Assert.IsTrue(actualScopes.Contains(expectedScope));
            }
        }
 internal /* for test only */ MsalAccessTokenCacheItem(string scopes)
 {
     CredentialType = StorageJsonValues.CredentialTypeAccessToken;
     _scopes        = scopes;
     ScopeSet       = ScopeHelper.ConvertStringToScopeSet(_scopes);
 }