IPlus.Authentication.OpenIdConnect 1.0.0

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

iPlusOIDC

This repository contains the code to connect to iPlusOIDC in a very simple way

appsettings.json configuration

The file path and other settings can be read from JSON configuration if desired.

In appsettings.json add a "iPlusOIDCSetting" properties:

{
   "iPlusOIDCSetting": {
    "Authority": "https://login.iplus.tech",
    "ClientId": "aa361a16-a9c0-4aea-971d-753d5135597d",
    "ClientSecret": "49C1A7E10C794A89A3D6A37998FB86B0",
    "ResponseType": [ "code" ],
    "Scope": [ "iplus.write", "iplus.read", "offline_access" ],
    "AudienceUrl": "https://api.iplus.tech/"
  }
}

And then pass the configuration section to the next methods in 'ConfigureServices':

services.AddIPlusOIDC(Configuration);

Example of a controller using dependency injection userHttpClient or clientHttpClient

[Authorize]
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;
        private readonly HttpClient _httpClient;

        public HomeController(ILogger<HomeController> logger, IHttpClientFactory factory)
        {
            _logger = logger;
            _httpClient = factory.CreateClient("userHttpClient");
        }

        public async Task<IActionResult> CallApi()
        {
            var content = await _httpClient.GetStringAsync("identity");

            ViewBag.Json = content;
            return View("json");
        }

        public IActionResult Logout()
        {
            return SignOut("Cookies", "oidc");
        }
    }

API configuration

In appsettings.json add a "IPlusJwtBearerSetting" properties:

{
   "IPlusJwtBearerSetting": {
    "Authority": "https://localhost:5001",
    "Audience": "iplus"
  }
}

And then pass the configuration section to the next methods in 'ConfigureServices':

services.AddJwtBearerAuthentication(Configuration);

Client backchannel configuration to request token with client credentials

Add the following usings

using iPlusOIDC.Extensions; using iPlusOIDC.Settings;

Example using httpClient with client credentials token

var iPlusOIDCSetting = new IPlusOIDCSetting
{
    Authority = "https://localhost:5001",
    ClientId = "786a5e12-c6f1-41f3-874c-459c012a6e4d",
    ClientSecret = "511536EFF270405880CA1C89C192F69A",
    Scope = new List<string> { "iplus.write", "iplus.read" },
    AudienceUrl = "https://localhost:6001/"
};

var apiClient = await new HttpClient().RequestTokenClientAsync(iPlusOIDCSetting);

var response = await apiClient.GetAsync("endpoint");
if (!response.IsSuccessStatusCode)
{
    Console.WriteLine(response.StatusCode);
}
else
{
    var content = await response.Content.ReadAsStringAsync();
    Console.WriteLine(content);
}
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 656 10/11/2021