-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable the authentication scheme name to be specified when conf…
…iguring subscription authentication (#111)
- Loading branch information
1 parent
0c3da94
commit 4b4c812
Showing
26 changed files
with
698 additions
and
286 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
|
||
namespace LiveDocs.GraphQLApi.Security; | ||
|
||
/// <summary> | ||
/// Represents the parameters required for generating a JWT token. | ||
/// </summary> | ||
public class TokenParameters | ||
{ | ||
/// <summary> | ||
/// The issuer of the token. If not provided, the default JwtUtil.Issuer is used. | ||
/// </summary> | ||
public string? Issuer { get; init; } = JwtUtil.Issuer; | ||
|
||
/// <summary> | ||
/// The audience of the token. If not provided, the default JwtUtil.Audience is used. | ||
/// </summary> | ||
public string? Audience { get; init; } = JwtUtil.Audience; | ||
|
||
/// <summary> | ||
/// The secret key used to sign the token. If not provided, the default JwtUtil.SecretKey is used. | ||
/// </summary> | ||
public string? SecretKey { get; init; } = JwtUtil.SecretKey; | ||
|
||
/// <summary> | ||
/// The expiration time of the token. If not provided, the token will expire in 120 minutes | ||
/// </summary> | ||
public DateTime? Expires { get; init; } = DateTime.UtcNow.AddMinutes(120); | ||
} |
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,34 @@ | ||
// src\RxDBDotNet\Configuration\DocumentOptions.cs | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using RxDBDotNet.Documents; | ||
|
||
namespace RxDBDotNet.Configuration; | ||
|
||
/// <summary> | ||
/// Provides configuration options for replicating documents of type <typeparamref name="TDocument"/>. | ||
/// </summary> | ||
/// <typeparam name="TDocument"> | ||
/// The type of document to be replicated, which must implement <see cref="IReplicatedDocument"/>. | ||
/// </typeparam> | ||
public sealed class DocumentOptions<TDocument> | ||
where TDocument : IReplicatedDocument | ||
{ | ||
/// <summary> | ||
/// Gets the document-level security options for documents of type <typeparamref name="TDocument"/>. | ||
/// These options control authorization and access control for specific document types. | ||
/// For global security settings like authentication schemes, see <see cref="ReplicationOptions.Security"/>. | ||
/// </summary> | ||
public DocumentSecurityOptions<TDocument> Security { get; set; } = new(); | ||
|
||
/// <summary> | ||
/// Gets the list of error types that can occur when pushing changes for documents of type <typeparamref name="TDocument"/>. | ||
/// See <see href="https://chillicream.com/docs/hotchocolate/v13/defining-a-schema/mutations/#errors">Hot Chocolate Mutation Errors</see> for more information. | ||
/// </summary> | ||
/// <remarks> | ||
/// These error types are used to handle specific exceptions that may be thrown | ||
/// during the document replication process. | ||
/// </remarks> | ||
public List<Type> Errors { get; } = []; | ||
} |
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
6 changes: 4 additions & 2 deletions
6
src/RxDBDotNet/Security/PolicyRequirement.cs → ...DotNet/Configuration/PolicyRequirement.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
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 @@ | ||
// src\RxDBDotNet\Configuration\ReplicationOptions.cs | ||
|
||
namespace RxDBDotNet.Configuration; | ||
|
||
/// <summary> | ||
/// Provides global configuration options for RxDB replication. | ||
/// </summary> | ||
public class ReplicationOptions | ||
{ | ||
/// <summary> | ||
/// Gets security-related configuration options. | ||
/// </summary> | ||
public SecurityOptions Security { get; } = new(); | ||
} |
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 @@ | ||
// src\RxDBDotNet\Configuration\SecurityOptions.cs | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.AspNetCore.Authentication.JwtBearer; | ||
namespace RxDBDotNet.Configuration; | ||
|
||
/// <summary> | ||
/// Provides global security-related configuration options for RxDB replication. | ||
/// </summary> | ||
public class SecurityOptions | ||
{ | ||
private readonly List<string> _subscriptionAuthenticationSchemes = [JwtBearerDefaults.AuthenticationScheme]; | ||
|
||
/// <summary> | ||
/// Gets the authentication schemes used for validating Subscription JWT tokens. | ||
/// The default value is a list containing only JwtBearerDefaults.AuthenticationScheme. | ||
/// </summary> | ||
public IReadOnlyList<string> SubscriptionAuthenticationSchemes => _subscriptionAuthenticationSchemes; | ||
|
||
/// <summary> | ||
/// Adds an authentication scheme to be used for WebSocket authentication if not already added. | ||
/// </summary> | ||
/// <param name="scheme">The authentication scheme to add.</param> | ||
/// <returns>The current SecurityOptions instance for method chaining.</returns> | ||
public SecurityOptions TryAddSubscriptionAuthenticationScheme(string scheme) | ||
{ | ||
if (!_subscriptionAuthenticationSchemes.Contains(scheme)) | ||
{ | ||
_subscriptionAuthenticationSchemes.Add(scheme); | ||
} | ||
return this; | ||
} | ||
} |
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.