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
                    
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="Vestfold.Extensions.Authentication" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Vestfold.Extensions.Authentication" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Vestfold.Extensions.Authentication" />
                    
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 Vestfold.Extensions.Authentication --version 1.0.3
                    
#r "nuget: Vestfold.Extensions.Authentication, 1.0.3"
                    
#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 Vestfold.Extensions.Authentication@1.0.3
                    
#: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=Vestfold.Extensions.Authentication&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Vestfold.Extensions.Authentication&version=1.0.3
                    
Install as a Cake Tool

NuGet Version NuGet Downloads

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 a Microsoft.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 a Azure.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 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.

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.

Version Downloads Last Updated
1.0.3 5 8/2/2025
1.0.2 93 5/24/2025
1.0.1 70 5/24/2025
1.0.0 107 5/23/2025