joelbyford.BasicAuth
1.1.1
See the version list below for details.
dotnet add package joelbyford.BasicAuth --version 1.1.1
NuGet\Install-Package joelbyford.BasicAuth -Version 1.1.1
<PackageReference Include="joelbyford.BasicAuth" Version="1.1.1" />
<PackageVersion Include="joelbyford.BasicAuth" Version="1.1.1" />
<PackageReference Include="joelbyford.BasicAuth" />
paket add joelbyford.BasicAuth --version 1.1.1
#r "nuget: joelbyford.BasicAuth, 1.1.1"
#:package joelbyford.BasicAuth@1.1.1
#addin nuget:?package=joelbyford.BasicAuth&version=1.1.1
#tool nuget:?package=joelbyford.BasicAuth&version=1.1.1
Code Modifications
Once installed, to use the library, simply modify the Configure method in your startup.cs to call the library in any one of two ways:
Authorize a Single User
For simple use cases, this may satisfy your need. PLEASE take steps to avoid having credentials in code
using joelbyford;
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
string basicAuthRealm = "mywebsite.com";
string basicAuthUser = "testUser"; //hardcoded values here for example only
string basicAuthPass = "testPass"; //hardcoded values here for example only
app.UseMiddleware<joelbyford.BasicAuth>(basicAuthRealm, basicAuthUser, basicAuthPass);
}
Authorize a Dictionary of Users
If you would like to control how and where you get the users and passwords from, this method is best (e.g. you are obtaining from a database). PLEASE take steps to avoid having credentials in code
using joelbyford;
using System.IO;
using System.Text.Json;
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
Dictionary<string, string> myUsers = new Dictionary<string, string>();
var packageJson = File.ReadAllText("authorizedUsers.json");
myUsers = JsonSerializer.Deserialize<Dictionary<string, string>>(packageJson);
string basicAuthRealm = "mywebsite.com";
app.UseMiddleware<joelbyford.BasicAuth>(basicAuthRealm, myUsers);
}
In this example, a json file is loaded from the web app's root directory with the following format:
{
"testUser" : "testPassword",
"devUser" : "devPassword"
}
This can of course be loaded in from a database call instead as long as users and passwords are loaded into a Dictionary<string, string>
To see an example of this in use, please see startup.cs in the https://github.com/joelbyford/CSVtoJSONcore repo.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net5.0
- Microsoft.AspNetCore.Http (>= 2.2.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.