HawkNet.AspNetCore 1.0.0

dotnet add package HawkNet.AspNetCore --version 1.0.0                
NuGet\Install-Package HawkNet.AspNetCore -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HawkNet.AspNetCore" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HawkNet.AspNetCore --version 1.0.0                
#r "nuget: HawkNet.AspNetCore, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install HawkNet.AspNetCore as a Cake Addin
#addin nuget:?package=HawkNet.AspNetCore&version=1.0.0

// Install HawkNet.AspNetCore as a Cake Tool
#tool nuget:?package=HawkNet.AspNetCore&version=1.0.0                

HawkNet.AspNetCore

  • 支援 asp.net core 8 提供 Hawk驗證。
  • Hawk 核心函數移植自 https://github.com/pcibraro/hawknet
    • 因原作者很久沒有維護了,自行移植比較保險
  • 性能考量 暫不提供 Hawk 內容Hash驗證的部分。

註冊HAWK驗證

 // 授權服務註冊
builder.Services.AddAuthentication()
    // 註冊Hawk驗證
    .AddHawkAuthorize(opt =>
    {
        // 設定證書
        opt.Credentials.Add(new HawkNet.AspNetCore.HawkCredential
        {
            Id = "123",
            Key = "werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn",
            Algorithm = "sha256",
            User = "Admin",
            Roles= ["Admins"]
        });

		// 也可以自行實作取得證書方法
        //opt.GetCredentialFunc = (id) => Task.FromResult(new HawkNet.AspNetCore.HawkCredential());
    });

啟用授權驗證

	// 啟用憑證檢驗 確定憑證有效性
	app.UseAuthentication();
	// 啟用權限驗證機制 檢查你是否有權限存取方法
	app.UseAuthorization();

ApiController 套用 Hawk驗證範例

    [ApiController]
    [Route("api/demo")]
    [Authorize(AuthenticationSchemes="Hawk", Roles ="Admins")]
    public class DemoController : ControllerBase
    {
        [AllowAnonymous]
        [HttpGet("Ping")]
        public string Ping() {
            return "Hello Ping AllowAnonymous";
        }

        [HttpGet("Hello")]
        public string Hello() {
            return "Hello Hawk Success";
        }
	}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 136 8/23/2024