-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce DisableAutoProtection and ExplicitResourceProtection; Refac…
…tor Middleware; Extend example app
- Loading branch information
Friedemann Braune
committed
May 4, 2024
1 parent
afb7d27
commit 377c015
Showing
4 changed files
with
96 additions
and
14 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
30 changes: 30 additions & 0 deletions
30
src/Keycloak.AuthServices.Authorization/ExplicitResourceProtectionAttribute.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,30 @@ | ||
namespace Keycloak.AuthServices.Authorization; | ||
|
||
/// <summary> | ||
/// Use this attribute on a method when the <see cref="UriBasedResourceProtectionMiddleware"/> | ||
/// to exclude the method from uri based resource protection and set a specific resource name and scope instead. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method, Inherited = false)] | ||
public class ExplicitResourceProtectionAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// <see cref="ExplicitResourceProtectionAttribute"/> | ||
/// </summary> | ||
/// <param name="resourceName">The name of the resource a configured in Keycloak mandatory and unique "Name" field (also referred as RESOURCE_ID).</param> | ||
/// <param name="scope">A valid scope from the list of applied scopes to the resource.</param> | ||
public ExplicitResourceProtectionAttribute(string resourceName, string scope) | ||
{ | ||
this.ResourceName = resourceName; | ||
this.Scope = scope; | ||
} | ||
|
||
/// <summary> | ||
/// The resource name to authorize for. | ||
/// </summary> | ||
public string ResourceName { get; } | ||
|
||
/// <summary> | ||
/// The scope to authorize the resource for. | ||
/// </summary> | ||
public string Scope { get; } | ||
} |
10 changes: 10 additions & 0 deletions
10
...uthServices.Authorization/UriBasedResourceProtection/DisableUriBasedResourceProtection.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,10 @@ | ||
namespace Keycloak.AuthServices.Authorization; | ||
|
||
/// <summary> | ||
/// Use this attribute on a method when the <see cref="UriBasedResourceProtectionMiddleware"/> | ||
/// to exclude the method from uri based resource protection. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method, Inherited = false)] | ||
public class DisableUriBasedResourceProtectionAttribute : Attribute | ||
{ | ||
} |
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