Compare commits
3
Commits
1158f09b9a
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04f7458438 | ||
|
|
6721eb3b18 | ||
|
|
aea3bdba01 |
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,194 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using xCommons.Providers;
|
||||||
|
using xCommons.Attributes;
|
||||||
|
using xCommons.Configurations;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using xIdentityService.Interfaces;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using xIdentityService.Controllers;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
|
namespace xIdentityHelper.Controllers
|
||||||
|
{
|
||||||
|
public abstract class XTestIdentityControllerBase : XBaseTestIdentityController
|
||||||
|
{
|
||||||
|
protected XTestIdentityControllerBase(
|
||||||
|
ILogger<XTestIdentityControllerBase> logger,
|
||||||
|
XAppConfiguration appConfiguration,
|
||||||
|
IXIdentityProvider identityProvider,
|
||||||
|
XValidationProvider validationProvider
|
||||||
|
) : base(logger, appConfiguration, identityProvider, validationProvider)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Identity Actions ...
|
||||||
|
/// <summary>
|
||||||
|
/// API Read Scope ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message</returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("PassReadAccess")]
|
||||||
|
[Authorize(Policy = XPolicies.ReadAccess)]
|
||||||
|
public virtual ActionResult<string> PassReadAccess()
|
||||||
|
{
|
||||||
|
return Ok("Read Access Passed ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// API Write Scope ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message</returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("PassWriteAccess")]
|
||||||
|
[Authorize(Policy = XPolicies.WriteAccess)]
|
||||||
|
public virtual ActionResult<string> PassWriteAccess()
|
||||||
|
{
|
||||||
|
return Ok("Write Access Passed ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// API Admin Scope ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message</returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("PassAdminAccess")]
|
||||||
|
[Authorize(Policy = XPolicies.AdminAccess)]
|
||||||
|
public virtual ActionResult<string> PassAdminAccess()
|
||||||
|
{
|
||||||
|
return Ok("Admin Access Passed ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// API Manage Scope ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message</returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("PassManageAccess")]
|
||||||
|
[Authorize(Policy = XPolicies.ManageAccess)]
|
||||||
|
public virtual ActionResult<string> PassManageAccess()
|
||||||
|
{
|
||||||
|
return Ok("Manage Access Passed ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Action which returns a List of Authenticated User Claims ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message which represent current user's claims</returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("HiClaims")]
|
||||||
|
[Authorize(Policy = XPolicies.User)]
|
||||||
|
public virtual ActionResult<string> HiClaims()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = new
|
||||||
|
{
|
||||||
|
name = User.Identity.Name,
|
||||||
|
claims = User.Claims.Select(c => new
|
||||||
|
{
|
||||||
|
c.Type,
|
||||||
|
c.Value
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Hello User for Checking Authentication and Policy ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message which contains authenticated user name</returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("HiUser")]
|
||||||
|
[Authorize(Policy = XPolicies.User)]
|
||||||
|
public virtual ActionResult<string> HiUser()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = $"Hi User: {User.Identity.Name} ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Hello User for Checking Authentication and Policy ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message which contains authenticated user name</returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("HiEnabledUser")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||||
|
public virtual ActionResult<string> HiEnabledUser()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = $"Hi User: {User.Identity.Name} is Enabled ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Hello User for Checking Authentication and Policy ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message which contains authenticated user name</returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("HiAgent")]
|
||||||
|
[Authorize(Policy = XPolicies.Agent)]
|
||||||
|
public virtual ActionResult<string> HiAgent()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = $"Hi Agent: {User.Identity.Name} ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Hello User for Checking Authentication and Policy ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message which contains authenticated user name</returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("HiEnabledAgent")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledAgent)]
|
||||||
|
public virtual ActionResult<string> HiEnabledAgent()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = $"Hi Agent: {User.Identity.Name} is Enabled ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Hello User for Checking Authentication and Policy ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message which contains authenticated user name</returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("HiAdmin")]
|
||||||
|
[Authorize(Policy = XPolicies.Admin)]
|
||||||
|
public virtual ActionResult<string> HiAdmin()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = $"Hi Admin: {User.Identity.Name} ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a simple Hello User for Checking Authentication and Policy ...
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>string message which contains authenticated user name</returns>
|
||||||
|
[RequireXPowered]
|
||||||
|
[HttpGet("HiEnabledAdmin")]
|
||||||
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
||||||
|
public virtual ActionResult<string> HiEnabledAdmin()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = $"Hi Admin: {User.Identity.Name} is Enabled ...";
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,6 @@ using xCommons.Authorization;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using static xIdentityHelper.XApiScopeHelper;
|
using static xIdentityHelper.XApiScopeHelper;
|
||||||
using xIdentityModels.Constants;
|
|
||||||
|
|
||||||
namespace xIdentityHelper
|
namespace xIdentityHelper
|
||||||
{
|
{
|
||||||
@@ -599,70 +598,6 @@ namespace xIdentityHelper
|
|||||||
.Build()
|
.Build()
|
||||||
);
|
);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
|
||||||
// Apik Key Policies ...
|
|
||||||
#region ApiKey Policies ...
|
|
||||||
//
|
|
||||||
// Claims Requirements ...
|
|
||||||
|
|
||||||
// //
|
|
||||||
// // ApiKey Access Policy ...
|
|
||||||
// result.Add(XPolicies.ApiKeyAccess,
|
|
||||||
// new AuthorizationPolicyBuilder()
|
|
||||||
// .RequireClaim(
|
|
||||||
// JwtClaimTypes.Scope,
|
|
||||||
// XApiKeyScope.Read.GetStringValue(),
|
|
||||||
// XApiKeyScope.Write.GetStringValue(),
|
|
||||||
// XApiKeyScope.Manage.GetStringValue()
|
|
||||||
// )
|
|
||||||
// .Build()
|
|
||||||
// );
|
|
||||||
|
|
||||||
// //
|
|
||||||
// // ApiKey Read Policy ...
|
|
||||||
// result.Add(XPolicies.ApiKeyReadAccess,
|
|
||||||
// new AuthorizationPolicyBuilder()
|
|
||||||
// .RequireClaim(
|
|
||||||
// JwtClaimTypes.Scope,
|
|
||||||
// XApiKeyScope.Read.GetStringValue()
|
|
||||||
// )
|
|
||||||
// .Build()
|
|
||||||
// );
|
|
||||||
|
|
||||||
// //
|
|
||||||
// // ApiKey Write Policy ...
|
|
||||||
// result.Add(XPolicies.ApiKeyWriteAccess,
|
|
||||||
// new AuthorizationPolicyBuilder()
|
|
||||||
// .RequireClaim(
|
|
||||||
// JwtClaimTypes.Scope,
|
|
||||||
// XApiKeyScope.Write.GetStringValue()
|
|
||||||
// )
|
|
||||||
// .Build()
|
|
||||||
// );
|
|
||||||
|
|
||||||
// //
|
|
||||||
// // ApiKey Manage Policy ...
|
|
||||||
// result.Add(XPolicies.ApiKeyManageAccess,
|
|
||||||
// new AuthorizationPolicyBuilder()
|
|
||||||
// .RequireClaim(
|
|
||||||
// JwtClaimTypes.Scope,
|
|
||||||
// XApiKeyScope.Manage.GetStringValue()
|
|
||||||
// )
|
|
||||||
// .Build()
|
|
||||||
// );
|
|
||||||
|
|
||||||
// //
|
|
||||||
// // ApiKey Admin Policy ...
|
|
||||||
// result.Add(XPolicies.ApiKeyAdminAccess,
|
|
||||||
// new AuthorizationPolicyBuilder()
|
|
||||||
// .RequireClaim(
|
|
||||||
// JwtClaimTypes.Scope,
|
|
||||||
// XApiKeyScope.Admin.GetStringValue()
|
|
||||||
// )
|
|
||||||
// .Build()
|
|
||||||
// );
|
|
||||||
#endregion
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user