-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented special auth0 client credential flow
- Loading branch information
1 parent
e7bd8cd
commit 96a6cfe
Showing
3 changed files
with
97 additions
and
17 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
71 changes: 71 additions & 0 deletions
71
src/Fancy.ResourceLinker.Gateway/Routing/Auth/Auth0ClientCredentialOnlyAuthStrategy.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,71 @@ | ||
using Fancy.ResourceLinker.Gateway.Authentication; | ||
using Fancy.ResourceLinker.Gateway.Common; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Fancy.ResourceLinker.Gateway.Routing.Auth; | ||
|
||
/// <summary> | ||
/// A route authentication strategy running the OAuth client credential flow only. | ||
/// </summary> | ||
/// <remarks> | ||
/// In some situations, auth0 requires an audience parameter in the request. This once can be added with this auth strategy. | ||
/// </remarks> | ||
internal class Auth0ClientCredentialOnlyAuthStrategy : ClientCredentialOnlyAuthStrategy | ||
{ | ||
/// <summary> | ||
/// The name of the auth strategy. | ||
/// </summary> | ||
public new const string NAME = "Auth0ClientCredentialOnly"; | ||
|
||
// <summary> | ||
/// The auth0 audience. | ||
/// </summary> | ||
private string _audience = string.Empty; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ClientCredentialOnlyAuthStrategy" /> class. | ||
/// </summary> | ||
/// <param name="discoveryDocumentService">The discovery document service.</param> | ||
/// <param name="logger">The logger.</param> | ||
public Auth0ClientCredentialOnlyAuthStrategy(DiscoveryDocumentService discoveryDocumentService, ILogger<Auth0ClientCredentialOnlyAuthStrategy> logger) : base(discoveryDocumentService, logger) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets the name of the strategy. | ||
/// </summary> | ||
/// <value> | ||
/// The name. | ||
/// </value> | ||
public override string Name => NAME; | ||
|
||
/// <summary> | ||
/// Initializes the authentication strategy based on the gateway authentication settings and the route authentication settings asynchronous. | ||
/// </summary> | ||
/// <param name="gatewayAuthenticationSettings">The gateway authentication settigns.</param> | ||
/// <param name="routeAuthenticationSettings">The route authentication settigns.</param> | ||
public override Task InitializeAsync(GatewayAuthenticationSettings? gatewayAuthenticationSettings, RouteAuthenticationSettings routeAuthenticationSettings) | ||
{ | ||
if (routeAuthenticationSettings.Options.ContainsKey("Audience")) | ||
{ | ||
_audience = routeAuthenticationSettings.Options["Audience"]; | ||
} | ||
|
||
return base.InitializeAsync(gatewayAuthenticationSettings, routeAuthenticationSettings); | ||
} | ||
|
||
/// <summary> | ||
/// Sets up the token request. | ||
/// </summary> | ||
/// <returns>The token request.</returns> | ||
protected override Dictionary<string, string> SetUpTokenRequest() | ||
{ | ||
return new Dictionary<string, string> | ||
{ | ||
{ "grant_type", "client_credentials" }, | ||
{ "client_id", _clientId }, | ||
{ "client_secret", _clientSecret }, | ||
{ "scope", _scope } | ||
}; | ||
} | ||
} |
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