BasicAuth.AspNetCore 1.0.0

dotnet add package BasicAuth.AspNetCore --version 1.0.0
                    
NuGet\Install-Package BasicAuth.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="BasicAuth.AspNetCore" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BasicAuth.AspNetCore" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="BasicAuth.AspNetCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BasicAuth.AspNetCore --version 1.0.0
                    
#r "nuget: BasicAuth.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.
#:package BasicAuth.AspNetCore@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BasicAuth.AspNetCore&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=BasicAuth.AspNetCore&version=1.0.0
                    
Install as a Cake Tool

Basic.AspNetCore

  • 支援 asp.net core 8 提供 Basic驗證。

註冊Basic驗證

 // 授權服務註冊
builder.Services.AddAuthentication()
    // 註冊Basic驗證
    .AddBasicAuthorize(opt =>
    {
        // 設定證書
        opt.Credentials.Add(new BasicAuth.AspNetCore.BasicCredential
        {
            Account = "admin",
            PassCode = "admin1234",
            User = "Admin",
            Roles = [ "Admins" ]
        });

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

啟用授權驗證

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

ApiController 套用 Basic驗證範例

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

        [HttpGet("Hello")]
        public string Hello() {
            return "Hello Basic Auth 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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 319 4/25/2025