-
Notifications
You must be signed in to change notification settings - Fork 164
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 sessions and refresh-tokens end-points
- Loading branch information
Showing
23 changed files
with
749 additions
and
0 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,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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Auth0.ManagementApi.Models.RefreshTokens | ||
{ | ||
/// <summary> | ||
/// Device used while issuing/exchanging the refresh token/Session | ||
/// </summary> | ||
public class Device | ||
{ | ||
/// <summary> | ||
/// First IP address associated with the refresh token/Session | ||
/// </summary> | ||
[JsonProperty("initial_ip")] | ||
public string InitialIp { get; set; } | ||
|
||
/// <summary> | ||
/// First autonomous system number associated with the refresh token/Session | ||
/// </summary> | ||
[JsonProperty("initial_asn")] | ||
public string InitialAsn { get; set; } | ||
|
||
/// <summary> | ||
/// First user agent associated with the refresh token/Session | ||
/// </summary> | ||
[JsonProperty("initial_user_agent")] | ||
public string InitialUserAgent { get; set; } | ||
|
||
/// <summary> | ||
/// Last IP address associated with the refresh token/Session | ||
/// </summary> | ||
[JsonProperty("last_ip")] | ||
public string LastIp { get; set; } | ||
|
||
/// <summary> | ||
/// Last autonomous system number associated with the refresh token/Session | ||
/// </summary> | ||
[JsonProperty("last_asn")] | ||
public string LastAsn { get; set; } | ||
|
||
/// <summary> | ||
/// Last user agent associated with the refresh token/Session | ||
/// </summary> | ||
[JsonProperty("last_user_agent")] | ||
public string LastUserAgent { get; set; } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Auth0.ManagementApi/Models/RefreshTokens/RefreshTokenGetRequest.cs
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,13 @@ | ||
namespace Auth0.ManagementApi.Models.RefreshTokens | ||
{ | ||
/// <summary> | ||
/// Represents the information required to Get <see cref="RefreshTokenInformation"/> | ||
/// </summary> | ||
public class RefreshTokenGetRequest | ||
{ | ||
/// <summary> | ||
/// ID of the refresh token to retrieve | ||
/// </summary> | ||
public string Id { get; set; } | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Auth0.ManagementApi/Models/RefreshTokens/RefreshTokenInformation.cs
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,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
||
namespace Auth0.ManagementApi.Models.RefreshTokens | ||
{ | ||
public class RefreshTokenInformation : SessionsBase | ||
{ | ||
/// <summary> | ||
/// ID of the client application granted with this refresh token | ||
/// </summary> | ||
[JsonProperty("client_id")] | ||
public string ClientId { get; set; } | ||
|
||
/// <summary> | ||
/// ID of the authenticated session used to obtain this refresh-token | ||
/// </summary> | ||
[JsonProperty("session_id")] | ||
public string SessionId { get; set; } | ||
|
||
/// <summary> | ||
/// True if the token is a rotating refresh token | ||
/// </summary> | ||
[JsonProperty("rotating")] | ||
public bool? Rotating { get; set; } | ||
|
||
/// <summary> | ||
/// <inheritdoc cref="Auth0.ManagementApi.Models.RefreshTokens.ResourceServer"/> | ||
/// </summary> | ||
[JsonProperty("resource_servers")] | ||
public IList<ResourceServer> ResourceServers { get; set; } | ||
|
||
/// <summary> | ||
/// The date and time when the refresh token was last exchanged | ||
/// </summary> | ||
[JsonProperty("last_exchanged_at")] | ||
public DateTime? LastExchangedAt { get; set; } | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Auth0.ManagementApi/Models/RefreshTokens/ResourceServer.cs
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,18 @@ | ||
namespace Auth0.ManagementApi.Models.RefreshTokens | ||
{ | ||
/// <summary> | ||
/// A list of the resource server IDs associated to this refresh-token and their granted scopes | ||
/// </summary> | ||
public class ResourceServer | ||
{ | ||
/// <summary> | ||
/// Resource server ID | ||
/// </summary> | ||
public string Audience { get; set; } | ||
|
||
/// <summary> | ||
/// List of scopes for the refresh token | ||
/// </summary> | ||
public string Scopes { get; set; } | ||
} | ||
} |
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,14 @@ | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
||
namespace Auth0.ManagementApi.Models.Sessions | ||
{ | ||
public class Authentication | ||
{ | ||
/// <summary> | ||
/// Contains the authentication methods a user has completed during their session | ||
/// </summary> | ||
[JsonProperty("methods")] | ||
public IList<AuthenticationMethods> Methods { get; set; } | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Auth0.ManagementApi/Models/Sessions/AuthenticationMethods.cs
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,29 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
|
||
namespace Auth0.ManagementApi.Models.Sessions | ||
{ | ||
/// <summary> | ||
/// Authentication signal details | ||
/// </summary> | ||
public class AuthenticationMethods | ||
{ | ||
/// <summary> | ||
/// One of: "federated", "passkey", "pwd", "sms", "email", "mfa", "mock" or a custom method denoted by a URL | ||
/// </summary> | ||
[JsonProperty("name")] | ||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// Timestamp of when the signal was received | ||
/// </summary> | ||
[JsonProperty("timestamp")] | ||
public DateTime? Timestamp { get; set; } | ||
|
||
/// <summary> | ||
/// A specific MFA factor. Only present when "name" is set to "mfa" | ||
/// </summary> | ||
[JsonProperty("^type$")] | ||
public string Type { get; set; } | ||
} | ||
} |
Oops, something went wrong.