Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion PropelAuth/PropelAuthExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,14 @@ private static void ConfigureAuthentication(IServiceCollection services, PropelA
});
}

services.AddAuthorization();
if (options.ConfigureAuthorization != null)
{
services.AddAuthorization(options.ConfigureAuthorization);
}
else
{
services.AddAuthorization();
}
}

/// <summary>
Expand Down
23 changes: 16 additions & 7 deletions PropelAuth/PropelAuthOptions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.AspNetCore.Authorization;

namespace PropelAuth.Models
{
/// <summary>
Expand Down Expand Up @@ -30,6 +32,11 @@
/// </summary>
public OAuthOptions? OAuthOptions { get; }

/// <summary>
/// Gets the action to configure authorization options including custom policies.
/// </summary>
public Action<AuthorizationOptions>? ConfigureAuthorization { get; }

#endregion

#region Constructors
Expand All @@ -41,22 +48,24 @@
/// <param name="apiKey">The API key used for authenticating requests to PropelAuth.</param>
/// <param name="publicKey">Optional. The public key used for token verification.</param>
/// <param name="oAuthOptions">Optional. The OAuth options if you are using PropelAuth's OAuth feature.</param>
/// <param name="configureAuthorization">Optional. Action to configure authorization options including custom policies.</param>
public PropelAuthOptions(string authUrl, string apiKey, string? publicKey = null,
OAuthOptions? oAuthOptions = null)
OAuthOptions? oAuthOptions = null, Action<AuthorizationOptions>? configureAuthorization = null)
{
AuthUrl = authUrl;
ApiKey = apiKey;
PublicKey = publicKey;
OAuthOptions = oAuthOptions;
ConfigureAuthorization = configureAuthorization;
}

#endregion
}

public class OAuthOptions

Check warning on line 65 in PropelAuth/PropelAuthOptions.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Missing XML comment for publicly visible type or member 'OAuthOptions'
{
#region Properties

/// <summary>
/// The client ID for the OAuth application.
/// </summary>
Expand All @@ -71,24 +80,25 @@
/// The callback path for the OAuth application. Defaults to "/callback"
/// </summary>
public string? CallbackPath { get; }

/// <summary>
/// Whether to allow requests via an authorization header `Bearer {TOKEN}`. Default false.
/// </summary>
public bool? AllowBearerTokenAuth { get; }

#endregion

#region Constructor

/// <summary>
/// Initializes a new instance of the <see cref="OAuthOptions"/> class.
/// </summary>
/// <param name="clientId">The client ID for the OAuth application.</param>
/// <param name="clientSecret">The client secret for the OAuth application.</param>
/// <param name="callbackPath">Optional. The callback path for the OAuth application. Defaults to "/callback"</param>
/// <param name="allowBearerTokenAuth">Optional. Whether to allow requests via an authorization header `Bearer {TOKEN}`. Default false.</param>
public OAuthOptions(string clientId, string clientSecret, string? callbackPath = "/callback", bool? allowBearerTokenAuth = false)
public OAuthOptions(string clientId, string clientSecret, string? callbackPath = "/callback",
bool? allowBearerTokenAuth = false)
{
ClientId = clientId;
ClientSecret = clientSecret;
Expand All @@ -97,6 +107,5 @@
}

#endregion

}
}
Loading