public async Task RemoveReferenceTokenAsync_by_handle_should_delete_entity() { using var store = new RavenDbTestDriverWrapper().GetDocumentStore(); var serializer = new PersistentGrantSerializer(); var loggerMock = new Mock <ILogger <ReferenceTokenStore> >(); using var s1 = store.OpenAsyncSession(); await s1.StoreAsync(new Entity.ReferenceToken { Id = "test", ClientId = "test", Data = serializer.Serialize(new Token { ClientId = "test" }) }, $"{nameof(Entity.ReferenceToken)}/test"); await s1.SaveChangesAsync(); using var session = store.OpenAsyncSession(); var sut = new ReferenceTokenStore(new ScopedAsynDocumentcSession(session), serializer, loggerMock.Object); await sut.RemoveReferenceTokenAsync("test"); using var s2 = store.OpenAsyncSession(); var result = await s2.LoadAsync <Entity.ReferenceToken>($"{nameof(Entity.ReferenceToken)}/test"); Assert.Null(result); }
public async Task RemoveReferenceTokenAsync_should_not_throw_when_entity_not_exist() { using var store = new RavenDbTestDriverWrapper().GetDocumentStore(); var serializer = new PersistentGrantSerializer(); var loggerMock = new Mock <ILogger <ReferenceTokenStore> >(); using var session = store.OpenAsyncSession(); var sut = new ReferenceTokenStore(new ScopedAsynDocumentcSession(session), serializer, loggerMock.Object); await sut.RemoveReferenceTokenAsync("test"); using var s2 = store.OpenAsyncSession(); var result = await s2.LoadAsync <Entity.ReferenceToken>($"{nameof(Entity.ReferenceToken)}/test"); Assert.Null(result); }
// revoke access token only if it belongs to client doing the request private async Task <bool> RevokeAccessTokenAsync(TokenRevocationRequestValidationResult validationResult) { var token = await ReferenceTokenStore.GetReferenceTokenAsync(validationResult.Token); if (token != null) { if (token.ClientId == validationResult.Client.ClientId) { Logger.LogDebug("Access token revoked"); await ReferenceTokenStore.RemoveReferenceTokenAsync(validationResult.Token); } else { Logger.LogWarning("Client {clientId} tried to revoke an access token belonging to a different client: {clientId}", validationResult.Client.ClientId, token.ClientId); } return(true); } return(false); }