Ejemplo n.º 1
0
        private RefreshTokenCacheItem FindRefreshTokenCommon(AuthenticationRequestParameters requestParam)
        {
            lock (LockObject)
            {
                requestParam.RequestContext.Logger.Info("Looking up refresh token in the cache..");
                if (requestParam.Authority == null)
                {
                    return(null);
                }

                RefreshTokenCacheKey key = new RefreshTokenCacheKey(
                    requestParam.Authority.Host, requestParam.ClientId,
                    requestParam.User?.Identifier);
                TokenCacheNotificationArgs args = new TokenCacheNotificationArgs
                {
                    TokenCache = this,
                    ClientId   = ClientId,
                    User       = requestParam.User
                };

                OnBeforeAccess(args);
                RefreshTokenCacheItem refreshTokenCacheItem =
                    JsonHelper.DeserializeFromJson <RefreshTokenCacheItem>(
                        TokenCacheAccessor.GetRefreshToken(key.ToString()));
                OnAfterAccess(args);

                requestParam.RequestContext.Logger.Info("Refresh token found in the cache? - " + (refreshTokenCacheItem != null));
                return(refreshTokenCacheItem);
            }
        }
Ejemplo n.º 2
0
        public void GetRefreshTokenDifferentEnvironmentTest()
        {
            TokenCache cache = new TokenCache()
            {
                ClientId = TestConstants.ClientId
            };
            RefreshTokenCacheItem rtItem = new RefreshTokenCacheItem()
            {
                Environment      = TestConstants.SovereignEnvironment,
                ClientId         = TestConstants.ClientId,
                RefreshToken     = "someRT",
                RawClientInfo    = MockHelpers.CreateClientInfo(),
                DisplayableId    = TestConstants.DisplayableId,
                IdentityProvider = TestConstants.IdentityProvider,
                Name             = TestConstants.Name
            };

            RefreshTokenCacheKey rtKey = rtItem.GetRefreshTokenItemKey();

            cache.TokenCacheAccessor.RefreshTokenCacheDictionary[rtKey.ToString()] = JsonHelper.SerializeToJson(rtItem);
            var authParams = new AuthenticationRequestParameters()
            {
                RequestContext = new RequestContext(Guid.Empty, null),
                ClientId       = TestConstants.ClientId,
                Authority      = Authority.CreateAuthority(TestConstants.AuthorityHomeTenant, false),
                Scope          = TestConstants.Scope,
                User           = TestConstants.User
            };

            Assert.IsNull(cache.FindRefreshToken(authParams));
        }
Ejemplo n.º 3
0
        public void ToStringTest()
        {
            RefreshTokenCacheKey key = new RefreshTokenCacheKey(TestConstants.ProductionEnvironment,
                                                                TestConstants.ClientId, TestConstants.UserIdentifier);

            Assert.IsNotNull(key);
            Assert.AreEqual(TestConstants.ProductionEnvironment, key.Environment);
            Assert.AreEqual(TestConstants.ClientId, key.ClientId);
            Assert.AreEqual(TestConstants.UserIdentifier, key.UserIdentifier);
        }
Ejemplo n.º 4
0
        public void GetRefreshTokenTest()
        {
            TokenCache cache = new TokenCache()
            {
                ClientId = TestConstants.ClientId
            };
            RefreshTokenCacheItem rtItem = new RefreshTokenCacheItem()
            {
                Environment      = TestConstants.ProductionEnvironment,
                ClientId         = TestConstants.ClientId,
                RefreshToken     = "someRT",
                RawClientInfo    = MockHelpers.CreateClientInfo(),
                DisplayableId    = TestConstants.DisplayableId,
                IdentityProvider = TestConstants.IdentityProvider,
                Name             = TestConstants.Name
            };

            rtItem.ClientInfo = ClientInfo.CreateFromJson(rtItem.RawClientInfo);

            RefreshTokenCacheKey rtKey = rtItem.GetRefreshTokenItemKey();

            cache.TokenCacheAccessor.RefreshTokenCacheDictionary[rtKey.ToString()] = JsonHelper.SerializeToJson(rtItem);
            var authParams = new AuthenticationRequestParameters()
            {
                RequestContext = new RequestContext(Guid.Empty, null),
                ClientId       = TestConstants.ClientId,
                Authority      = Authority.CreateAuthority(TestConstants.AuthorityHomeTenant, false),
                Scope          = TestConstants.Scope,
                User           = TestConstants.User
            };

            Assert.IsNotNull(cache.FindRefreshToken(authParams));

            // RT is stored by environment, client id and userIdentifier as index.
            // any change to authority (within same environment), uniqueid and displyableid will not
            // change the outcome of cache look up.
            Assert.IsNotNull(cache.FindRefreshToken(new AuthenticationRequestParameters()
            {
                RequestContext = new RequestContext(Guid.Empty, null),
                ClientId       = TestConstants.ClientId,
                Authority      = Authority.CreateAuthority(TestConstants.AuthorityHomeTenant + "more", false),
                Scope          = TestConstants.Scope,
                User           = TestConstants.User
            }));
        }