Vestfold.Extensions.Authentication
1.0.3
Prefix Reserved
dotnet add package Vestfold.Extensions.Authentication --version 1.0.3
NuGet\Install-Package Vestfold.Extensions.Authentication -Version 1.0.3
<PackageReference Include="Vestfold.Extensions.Authentication" Version="1.0.3" />
<PackageVersion Include="Vestfold.Extensions.Authentication" Version="1.0.3" />
<PackageReference Include="Vestfold.Extensions.Authentication" />
paket add Vestfold.Extensions.Authentication --version 1.0.3
#r "nuget: Vestfold.Extensions.Authentication, 1.0.3"
#:package Vestfold.Extensions.Authentication@1.0.3
#addin nuget:?package=Vestfold.Extensions.Authentication&version=1.0.3
#tool nuget:?package=Vestfold.Extensions.Authentication&version=1.0.3
Vestfold.Extensions.Authentication
Contains builder extensions to extend a dotnet core application with authentication functionality.
Usage in an Azure Function / Azure Web App
To set Graph base url
at a global level (optional, defaults to https://graph.microsoft.com/v1.0), add the following to your local.settings.json
file:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"GRAPH_BASE_URL": "https://graph.microsoft.com/v1.0",
"AZURE_CLIENT_ID": "your-azure-app-registration-client-id-guid",
"AZURE_CLIENT_SECRET": "your-azure-app-registration-client-secret",
"AZURE_TENANT_ID": "your-azure-tenant-id-guid"
}
}
Usage outside Azure
To set Graph base url
at a global level (optional, defaults to https://graph.microsoft.com/v1.0), add the following to your appsettings.json
file:
{
"GRAPH_BASE_URL": "https://graph.microsoft.com/v1.0",
"AZURE_CLIENT_ID": "your-azure-app-registration-client-id-guid",
"AZURE_CLIENT_SECRET": "your-azure-app-registration-client-secret",
"AZURE_TENANT_ID": "your-azure-tenant-id-guid"
}
Setting up for an Azure Function / Azure Web App
var builder = FunctionsApplication.CreateBuilder(args);
builder.ConfigureFunctionsWebApplication();
builder.Services.AddVestfoldAuthentication();
builder.Build().Run();
Setting up for a HostBuilder (Console app, ClassLibrary, etc.)
public static async Task Main(string[] args)
{
await Host.CreateDefaultBuilder(args)
.ConfigureServices(services => services.AddVestfoldAuthentication())
.Build()
.RunAsync();
await Serilog.Log.CloseAndFlushAsync();
}
Setting up for a WebApplicationBuilder (WebAPI, Blazor, etc.)
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddVestfoldAuthentication();
var app = builder.Build();
Using the authentication methods
To use the authentication methods, you inject the IAuthenticationService
into your classes.
Then you call:
CreateGraphClient
- which will return aMicrosoft.Graph.GraphServiceClient
that can be used to call the Microsoft Graph API (with the permissions granted to the app registration (AZURE_CLIENT_ID))GetAccessToken
- which will return aAzure.Core.AccessToken
for specified scopes from the app registration (AZURE_CLIENT_ID)
public class Something
{
private readonly GraphServiceClient _graphClient;
private readonly AccessToken _accessToken;
public Something(IAuthenticationService authenticationService)
{
// you can optionally pass a base URL for the Graph API, otherwise it will use the base URL from configuration, or the default base URL https://graph.microsoft.com/v1.0
// you can also optionally pass custom scopes, otherwise it will use the default scope https://graph.microsoft.com/.default
_graphClient = authenticationService.CreateGraphClient();
// you can optionally pass a boolean to specify if you want to enable logging for the Azure Credential token process, otherwise it will default to false
_accessToken = await authenticationService.GetAccessToken(["https://whatever.no/.default"]);
}
}
Product | Versions 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. |
-
net8.0
- Azure.Identity (>= 1.14.2)
- Microsoft.Extensions.Configuration (>= 9.0.7)
- Microsoft.Extensions.DependencyInjection (>= 9.0.7)
- Microsoft.Graph (>= 5.88.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Vestfold.Extensions.Authentication:
Package | Downloads |
---|---|
Vestfold.Extensions.Archive
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.