Exemplo n.º 1
0
        public async Task Test_blacklist_sequence()
        {
            string apiKey = GetVariable("AUTH0_API_KEY");

            var apiClient = new ManagementApiClient(GetVariable("AUTH0_TOKEN_BLACKLISTED_TOKENS"), new Uri(GetVariable("AUTH0_MANAGEMENT_API_URL")));

            // Get all the blacklisted tokens
            var tokensBefore = await apiClient.BlacklistedTokens.GetAllAsync(apiKey);

            // Generate a token which allows us to list all clients
            var scopes = new
            {
                clients = new
                {
                    actions = new string[] { "read" }
                }
            };
            string jti   = Guid.NewGuid().ToString("N");
            string token = GenerateToken(scopes, jti);

            // Confirm that the token is working
            var confirmationApiClient = new ManagementApiClient(token, new Uri(GetVariable("AUTH0_MANAGEMENT_API_URL")));
            var clients = await confirmationApiClient.Clients.GetAllAsync();

            clients.Should().NotBeNull();

            // Now blacklist that new token
            var blacklistRequest = new BlacklistedTokenCreateRequest
            {
                Aud = apiKey,
                Jti = jti
            };
            await apiClient.BlacklistedTokens.CreateAsync(blacklistRequest);

            // Get all the blacklisted tokens and check that we have one more
            var tokensAfter = await apiClient.BlacklistedTokens.GetAllAsync(apiKey);

            tokensAfter.Count.Should().Be(tokensBefore.Count + 1);

            // Try and get all the clients again with that token
            Func <Task> getFunc = async() => await confirmationApiClient.Clients.GetAllAsync();

            getFunc.ShouldThrow <ApiException>().And.ApiError.StatusCode.Should().Be(401);
        }
        public async Task Test_blacklist_sequence()
        {
            string apiKey = GetVariable("AUTH0_API_KEY");

            var apiClient = new ManagementApiClient(GetVariable("AUTH0_TOKEN_BLACKLISTED_TOKENS"), new Uri(GetVariable("AUTH0_MANAGEMENT_API_URL")));

            // Get all the blacklisted tokens
            var tokensBefore = await apiClient.BlacklistedTokens.GetAll(apiKey);

            // Generate a token which allows us to list all clients
            var scopes = new
            {
                clients = new
                {
                    actions = new string[] { "read" }
                }
            };
            string jti = Guid.NewGuid().ToString("N");
            string token = GenerateToken(scopes, jti);

            // Confirm that the token is working
            var confirmationApiClient = new ManagementApiClient(token, new Uri(GetVariable("AUTH0_MANAGEMENT_API_URL")));
            var clients = await confirmationApiClient.Clients.GetAll();
            clients.Should().NotBeNull();

            // Now blacklist that new token
            var blacklistRequest = new BlacklistedTokenCreateRequest
            {
                Aud = apiKey,
                Jti = jti
            };
            await apiClient.BlacklistedTokens.Create(blacklistRequest);

            // Get all the blacklisted tokens and check that we have one more
            var tokensAfter = await apiClient.BlacklistedTokens.GetAll(apiKey);
            tokensAfter.Count.Should().Be(tokensBefore.Count + 1);

            // Try and get all the clients again with that token
            Func<Task> getFunc = async () => await confirmationApiClient.Clients.GetAll();
            getFunc.ShouldThrow<ApiException>().And.ApiError.StatusCode.Should().Be(401);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Blacklists a JWY token.
 /// </summary>
 /// <param name="request">The <see cref="BlacklistedTokenCreateRequest" /> containing the information of the token to blacklist.</param>
 /// <returns>Task.</returns>
 public Task Create(BlacklistedTokenCreateRequest request)
 {
     return Connection.PostAsync<Core.Client>("blacklists/tokens", request, null, null, null, null, null);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Blacklists a JWT token.
 /// </summary>
 /// <param name="request">The <see cref="BlacklistedTokenCreateRequest" /> containing the information of the token to blacklist.</param>
 /// <returns>Task.</returns>
 public Task CreateAsync(BlacklistedTokenCreateRequest request)
 {
     return(Connection.PostAsync <Client>("blacklists/tokens", request, null, null, null, null, null));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Blacklists a JWT token.
 /// </summary>
 /// <param name="request">The <see cref="BlacklistedTokenCreateRequest"/> containing the information of the token to blacklist.</param>
 /// <returns>A <see cref="Task"/> that represents the asynchronous create operation.</returns>
 public Task CreateAsync(BlacklistedTokenCreateRequest request)
 {
     return(Connection.SendAsync <Client>(HttpMethod.Post, BuildUri("blacklists/tokens"), request, DefaultHeaders));
 }
Exemplo n.º 6
0
 public Task Create(BlacklistedTokenCreateRequest request)
 {
     return CreateAsync(request);
 }
Exemplo n.º 7
0
 public Task Create(BlacklistedTokenCreateRequest request)
 {
     return(CreateAsync(request));
 }