-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for session management and refresh-tokens (#737)
- Loading branch information
Showing
31 changed files
with
951 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("Auth0.ManagementApi.IntegrationTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100453e57bfa7549abf0f1775df9384d2f279d25c2ab4c78d5a69d7e6da9567d2b984da533229a0d530a3b75c7f5a12c341799b448102995b8a123d1288aa12ca3c1c354c3da97e64626d1223ca7c6e95cba845bce6edcee8b326c2cd015cc84995e5b630ef5c7fa69928dea64a53ee71a493267de7e18d0e9f31e1e00bb8e01cae")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using Auth0.ManagementApi.Models.RefreshTokens; | ||
|
||
namespace Auth0.ManagementApi.Clients | ||
{ | ||
public interface IRefreshTokenClient | ||
{ | ||
/// <summary> | ||
/// Retrieve refresh token information. | ||
/// </summary> | ||
/// <param name="request"><see cref="RefreshTokenGetRequest"/></param> | ||
/// <param name="cancellationToken"> <see cref="CancellationToken"/></param> | ||
/// <returns></returns> | ||
Task<RefreshTokenInformation> GetAsync(RefreshTokenGetRequest request, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Delete a refresh token by its Id. | ||
/// </summary> | ||
/// <param name="id">Id of the refresh token to delete.</param> | ||
/// <param name="cancellationToken"> <see cref="CancellationToken"/></param> | ||
/// <returns></returns> | ||
Task DeleteAsync(string id, CancellationToken cancellationToken = default); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Auth0.ManagementApi.Models.Sessions; | ||
|
||
namespace Auth0.ManagementApi.Clients | ||
{ | ||
public interface ISessionsClient | ||
{ | ||
/// <summary> | ||
/// Retrieve session information. | ||
/// </summary> | ||
/// <param name="request"><see cref="SessionsGetRequest"/></param> | ||
/// <param name="cancellationToken"> <see cref="CancellationToken"/></param> | ||
/// <returns></returns> | ||
Task<Sessions> GetAsync(SessionsGetRequest request, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Delete a session by Id. | ||
/// </summary> | ||
/// <param name="id">Id of the session to delete.</param> | ||
/// <param name="cancellationToken"> <see cref="CancellationToken"/></param> | ||
/// <returns></returns> | ||
Task DeleteAsync(string id, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Revokes a session by Id and all associated refresh tokens. | ||
/// </summary> | ||
/// <param name="id">Id of the session to revoke</param> | ||
/// <param name="cancellationToken"> <see cref="CancellationToken"/></param> | ||
/// <returns></returns> | ||
Task RevokeAsync(string id, CancellationToken cancellationToken = default); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Auth0.ManagementApi.Models.RefreshTokens; | ||
|
||
namespace Auth0.ManagementApi.Clients | ||
{ | ||
|
||
/// <inheritdoc cref="Auth0.ManagementApi.Clients.IRefreshTokenClient"/> | ||
public class RefreshTokenClient : BaseClient, IRefreshTokenClient | ||
{ | ||
private const string RefreshTokensBasePath = "refresh-tokens"; | ||
|
||
/// <summary> | ||
/// Initializes a new instance on <see cref="RefreshTokenClient"/> | ||
/// </summary> | ||
/// <param name="connection"><see cref="IManagementConnection"/> used to make all API calls.</param> | ||
/// <param name="baseUri"><see cref="Uri"/> of the endpoint to use in making API calls.</param> | ||
/// <param name="defaultHeaders">Dictionary containing default headers included with every request this client makes.</param> | ||
public RefreshTokenClient(IManagementConnection connection, Uri baseUri, IDictionary<string, string> defaultHeaders) | ||
: base(connection, baseUri, defaultHeaders) | ||
{ | ||
} | ||
|
||
/// <inheritdoc cref="Auth0.ManagementApi.Clients.IRefreshTokenClient.GetAsync"/> | ||
public Task<RefreshTokenInformation> GetAsync(RefreshTokenGetRequest request, CancellationToken cancellationToken = default) | ||
{ | ||
if (request == null) | ||
throw new ArgumentNullException(nameof(request)); | ||
|
||
if(string.IsNullOrEmpty(request.Id)) | ||
throw new ArgumentException("Value cannot be null or empty.", nameof(request.Id)); | ||
|
||
return Connection.GetAsync<RefreshTokenInformation>( | ||
BuildUri($"{RefreshTokensBasePath}/{EncodePath(request.Id)}"), | ||
DefaultHeaders, cancellationToken: cancellationToken); | ||
} | ||
|
||
/// <inheritdoc cref="Auth0.ManagementApi.Clients.IRefreshTokenClient.DeleteAsync"/> | ||
public Task DeleteAsync(string id, CancellationToken cancellationToken = default) | ||
{ | ||
return Connection.SendAsync<object>( | ||
HttpMethod.Delete, | ||
BuildUri($"{RefreshTokensBasePath}/{EncodePath(id)}"), | ||
null, DefaultHeaders, cancellationToken: cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Auth0.ManagementApi.Models.Sessions; | ||
|
||
namespace Auth0.ManagementApi.Clients | ||
{ | ||
|
||
/// <inheritdoc cref="Auth0.ManagementApi.Clients.ISessionsClient"/> | ||
public class SessionsClient : BaseClient, ISessionsClient | ||
{ | ||
private const string SessionsBasePath = "sessions"; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of <see cref="SessionsClient"/>. | ||
/// </summary> | ||
/// <param name="connection"></param> | ||
/// <param name="baseUri"></param> | ||
/// <param name="defaultHeaders"></param> | ||
public SessionsClient(IManagementConnection connection, Uri baseUri, IDictionary<string, string> defaultHeaders) | ||
: base(connection, baseUri, defaultHeaders) | ||
{ | ||
} | ||
|
||
/// <inheritdoc cref="Auth0.ManagementApi.Clients.ISessionsClient.GetAsync"/> | ||
public Task<Sessions> GetAsync(SessionsGetRequest request, CancellationToken cancellationToken = default) | ||
{ | ||
if (request == null) | ||
throw new ArgumentNullException(nameof(request)); | ||
|
||
if(string.IsNullOrEmpty(request.Id)) | ||
throw new ArgumentException("Value cannot be null or empty.", nameof(request.Id)); | ||
|
||
return Connection.GetAsync<Sessions>( | ||
BuildUri($"{SessionsBasePath}/{EncodePath(request.Id)}"), | ||
DefaultHeaders, cancellationToken: cancellationToken); | ||
} | ||
|
||
/// <inheritdoc cref="Auth0.ManagementApi.Clients.ISessionsClient.DeleteAsync"/> | ||
public Task DeleteAsync(string id, CancellationToken cancellationToken = default) | ||
{ | ||
return Connection.SendAsync<object>( | ||
HttpMethod.Delete, | ||
BuildUri($"{SessionsBasePath}/{EncodePath(id)}"), | ||
null, DefaultHeaders, cancellationToken: cancellationToken); | ||
} | ||
|
||
/// <inheritdoc cref="Auth0.ManagementApi.Clients.ISessionsClient.RevokeAsync"/> | ||
public Task RevokeAsync(string id, CancellationToken cancellationToken = default) | ||
{ | ||
return Connection.SendAsync<Task>(HttpMethod.Post, | ||
BuildUri($"{SessionsBasePath}/{EncodePath(id)}/revoke"), | ||
null, | ||
DefaultHeaders, cancellationToken: cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.