public async Task success_remove()
 {
     Should.NotThrow(() =>
     {
         _persistedGrantStore.RemoveAsync(_key).GetAwaiter();
     });
 }
Exemple #2
0
        public async Task Store_Grant_And_Remove_It()
        {
            var key = Guid.NewGuid().ToString("N");

            var grant = new IdentityServer4.Models.PersistedGrant
            {
                Key          = key,
                Expiration   = DateTime.UtcNow.AddDays(1),
                Type         = "test",
                ClientId     = "client1",
                SubjectId    = "sub1",
                SessionId    = "session1",
                CreationTime = DateTime.UtcNow,
                Description  = "des",
                Data         = "bla bla",
                ConsumedTime = DateTime.UtcNow
            };

            await persistedGrantStore.StoreAsync(grant);

            await persistedGrantStore.RemoveAsync(key);

            var item = await persistedGrantStore.GetAsync(key);

            item.Should().BeNull();
        }
Exemple #3
0
        /// <summary>
        /// Fulls the log out.
        /// </summary>
        /// <returns> </returns>
        private async Task FullLogOut()
        {
            var subjectId = User.Identity.GetSubjectId();

            var sessionId = await _userSession.GetSessionIdAsync().ConfigureAwait(false);

            var grants = await _persistedGrantStore.GetAllAsync(subjectId).ConfigureAwait(false);

            foreach (var persistedGrant in grants.Where(e => e.Data.Contains($"\"{sessionId}\"")))
            {
                await _persistedGrantStore.RemoveAsync(persistedGrant.Key).ConfigureAwait(false);
            }

            var keys = Request.Cookies.Keys;

            foreach (var key in keys)
            {
                Response.Cookies.Delete(key);
            }

            await _signInManager.SignOutAsync().ConfigureAwait(false);

            await HttpContext.SignOutAsync().ConfigureAwait(false);

            await _interaction.RevokeTokensForCurrentSessionAsync().ConfigureAwait(false);

            await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()))
            .ConfigureAwait(false);
        }
Exemple #4
0
        public async Task get_and_remove()
        {
            var key = _currentManyEntities[0].Key;

            var entity = await _persistedGrantStore.GetAsync(key);

            entity.Data.Should().Be(_currentManyEntities[0].Data);
            await _persistedGrantStore.RemoveAsync(key);
        }
        public async Task RemoveAsync(string key)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(key))
                {
                    throw new ArgumentNullException(
                              nameof(key),
                              "key can not be null or white space");
                }

                await _inner.RemoveAsync(key);

                var result = await _setFallBackPolicy
                             .ExecuteAsync(async() =>
                {
                    await _handle.cache.RemoveAsync <PersistedGrant>(
                        Utilities
                        .CreateCachedPersistedGrantStoreKey(key))
                    .ConfigureAwait(false);
                    return(true);
                }).ConfigureAwait(false);


                if (result)
                {
                    if (_debugLoggingEnabled)
                    {
                        _logger.LogDebug(
                            $"Persisted grants with key {key} " +
                            $"successfully removed");
                    }
                }
                else
                {
                    if (_errorLoggingEnabled)
                    {
                        _logger.LogError(
                            $"Caching problems with persistant store cache");
                    }
                }
            }
            catch (Exception ex)
            {
                if (_errorLoggingEnabled)
                {
                    _logger.LogError(
                        ex,
                        $"something went wrong with RemoveAsync for key {key}");
                }
                throw;
            }
        }
        /// <summary>	Did user consent already asynchronous. </summary>
        /// <param name="returnUrl">	URL of the return. </param>
        /// <param name="context">      The context. </param>
        /// <returns>	A Task&lt;bool&gt; </returns>
        public async Task <bool> DidUserConsentAlreadyAsync(string returnUrl, HttpContext context)
        {
            var user    = context.User;
            var request = await _interaction.GetAuthorizationContextAsync(returnUrl);

            if (request == null)
            {
                return(false);
            }
            var client = await _clientStore.FindEnabledClientByIdAsync(request.ClientId);

            if (client == null)
            {
                return(false);
            }

            var grants = await _grantStore.GetAllAsync(user.Claims.First(c => c.Type == "sub").Value);

            var grantedAlready = grants.SingleOrDefault(g => g.Type == "user_consent" && g.ClientId == client.ClientId &&
                                                        (!g.Expiration.HasValue || g.Expiration >= DateTime.UtcNow));

            if (grantedAlready == null)
            {
                return(false);
            }

            dynamic data    = JsonConvert.DeserializeObject(grantedAlready.Data);
            var     jScopes = data.Scopes;
            var     scopes  = new List <string>();

            foreach (var jScope in jScopes)
            {
                scopes.Add(jScope.ToString());
            }

            var grantedConsent = new ConsentResponse
            {
                RememberConsent = true,
                ScopesConsented = scopes
            };

            // delete the grant key to let IdSrv readd it
            await _grantStore.RemoveAsync(grantedAlready.Key);

            // signal allowed grant, savin persisted grant
            await _interaction.GrantConsentAsync(request, grantedConsent);

            return(true);
        }
        public async Task RemoveAsync_Should_Remove_PeristedGrant()
        {
            //Arrange
            await _persistedGrantStore.StoreAsync(new PersistedGrant
            {
                Key = "#1P3R"
            });

            //Act
            await _persistedGrantStore.RemoveAsync("#1P3R");

            //Assert
            var persistedGrant = await _persistedGrantStore.GetAsync("#1P3R");

            persistedGrant.ShouldBe(null);
        }
Exemple #8
0
        public async Task RemoveAsync_Should_Remove_PeristedGrant()
        {
            //Arrange
            await _persistedGrantStore.StoreAsync(new PersistedGrant
            {
                Key      = "#1P3R",
                Type     = "Type",
                ClientId = "ClientId",
                Data     = ""
            }).ConfigureAwait(false);

            //Act
            await _persistedGrantStore.RemoveAsync("#1P3R").ConfigureAwait(false);

            //Assert
            var persistedGrant = await _persistedGrantStore.GetAsync("#1P3R").ConfigureAwait(false);

            persistedGrant.ShouldBe(null);
        }
Exemple #9
0
        public void PersistedGrantStore()
        {
            IPersistedGrantStore store = Fixture.GetService <IPersistedGrantStore>();

            Client client = CreateClient();

            Provider.AddClientAsync(client).Wait();

            PersistedGrant grant1 = CreateGrant(client.ClientId, "aaa", "t1");
            PersistedGrant grant2 = CreateGrant(client.ClientId, "aaa");
            PersistedGrant grant3 = CreateGrant(client.ClientId, "aaa");
            PersistedGrant grant4 = CreateGrant(client.ClientId);
            PersistedGrant grant5 = CreateGrant(client.ClientId);

            store.StoreAsync(grant1).Wait();
            store.StoreAsync(grant2).Wait();
            store.StoreAsync(grant3).Wait();
            store.StoreAsync(grant4).Wait();
            store.StoreAsync(grant5).Wait();

            List <PersistedGrant> results = store.GetAllAsync("aaa").Result?.ToList();

            Assert.Equal(3, results.Count);

            store.RemoveAllAsync("aaa", grant1.ClientId, "t1").Wait();

            results = store.GetAllAsync("aaa").Result?.ToList();
            Assert.Equal(2, results.Count);

            store.RemoveAllAsync("aaa", grant1.ClientId).Wait();

            results = store.GetAllAsync("aaa").Result?.ToList();
            Assert.Empty(results);

            PersistedGrant result = store.GetAsync(grant5.Key).Result;

            Assert.NotNull(result);

            store.RemoveAsync(grant5.Key);
            result = store.GetAsync(grant5.Key).Result;
            Assert.Null(result);
        }
        public async Task RemoveAsync_WhenKeyOfExistingReceived_ExpectGrantDeleted()
        {
            // Arrange
            var persistedGrant = UniquePersistedGrant;

            // Act
            await _persistedGrantStore.StoreAsync(persistedGrant);

            var foundPersistedGrant = await _persistedGrantStore.GetAsync(persistedGrant.Key);

            Assert.IsNotNull(foundPersistedGrant);

            await _persistedGrantStore.RemoveAsync(persistedGrant.Key);

            foundPersistedGrant = await _persistedGrantStore.GetAsync(persistedGrant.Key);


            // Assert
            Assert.IsNull(foundPersistedGrant);
        }
Exemple #11
0
 public Task RemoveAsync(string key)
 {
     return(_inMemoryPersistedGrantStore.RemoveAsync(key));
 }
Exemple #12
0
 /// <summary>
 /// Removes the item.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <returns></returns>
 protected async Task RemoveItemAsync(string key)
 {
     key = GetHashedKey(key);
     await _store.RemoveAsync(key);
 }
Exemple #13
0
 async Task RemoveItem(string key, string type)
 {
     key = HashKey(key, type);
     await _store.RemoveAsync(key);
 }
 public Task RemoveAsync(string key)
 {
     return(_persistedGrantStoreImplementation.RemoveAsync(key));
 }