161 lines
4.8 KiB
C#
161 lines
4.8 KiB
C#
using System.Linq;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using xIdentityHelper;
|
|
using xCommons.Attributes;
|
|
using static IdentityServer4.IdentityServerConstants;
|
|
|
|
namespace xIds.Controllers
|
|
{
|
|
public partial class AccountController
|
|
{
|
|
|
|
//
|
|
#region Test Actions ...
|
|
/// <summary>
|
|
/// API Read Scope
|
|
/// </summary>
|
|
/// <returns>string message</returns>
|
|
[RequireXPowered]
|
|
[Authorize(LocalApi.PolicyName)]
|
|
[HttpGet("Test/PassReadAccess")]
|
|
[Authorize(Policy = XPolicies.ReadAccess)]
|
|
public ActionResult<string> PassReadAccess()
|
|
{
|
|
return Ok("Read Access Passed ...");
|
|
}
|
|
|
|
/// <summary>
|
|
/// API Write Scope
|
|
/// </summary>
|
|
/// <returns>string message</returns>
|
|
[RequireXPowered]
|
|
[Authorize(LocalApi.PolicyName)]
|
|
[HttpGet("Test/PassWriteAccess")]
|
|
[Authorize(Policy = XPolicies.WriteAccess)]
|
|
public ActionResult<string> PassWriteAccess()
|
|
{
|
|
return Ok("Write Access Passed ...");
|
|
}
|
|
|
|
/// <summary>
|
|
/// API Admin Scope
|
|
/// </summary>
|
|
/// <returns>string message</returns>
|
|
[RequireXPowered]
|
|
[Authorize(LocalApi.PolicyName)]
|
|
[HttpGet("Test/PassAdminAccess")]
|
|
[Authorize(Policy = XPolicies.AdminAccess)]
|
|
public ActionResult<string> PassAdminAccess()
|
|
{
|
|
return Ok("Admin Access Passed ...");
|
|
}
|
|
|
|
/// <summary>
|
|
/// API Manage Scop
|
|
/// </summary>
|
|
/// <returns>string message</returns>
|
|
[RequireXPowered]
|
|
[Authorize(LocalApi.PolicyName)]
|
|
[HttpGet("Test/PassManageAccess")]
|
|
[Authorize(Policy = XPolicies.ManageAccess)]
|
|
public 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("Test/HiClaims")]
|
|
[Authorize(LocalApi.PolicyName)]
|
|
[Authorize(Policy = XPolicies.User)]
|
|
public 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("Test/HiUser")]
|
|
[Authorize(LocalApi.PolicyName)]
|
|
[Authorize(Policy = XPolicies.User)]
|
|
public 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("Test/HiEnabledUser")]
|
|
[Authorize(LocalApi.PolicyName)]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public 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("Test/HiAdmin")]
|
|
[Authorize(LocalApi.PolicyName)]
|
|
[Authorize(Policy = XPolicies.Admin)]
|
|
public 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("Test/HiEnabledAdmin")]
|
|
[Authorize(LocalApi.PolicyName)]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public ActionResult<string> HiEnabledAdmin()
|
|
{
|
|
//
|
|
var result = $"Hi Admin: {User.Identity.Name} is Enabled ...";
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
#endregion
|
|
}
|
|
} |