Skip to content
.net-klient for generere access token fra Maskinporten
C#
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.dependabot
ExampleApplication
KS.Fiks.Maskinporten.Client.Tests
KS.Fiks.Maskinporten.Client
.gitignore
Jenkinsfile
LICENSE
MaskinportenClient.sln
README.md

README.md

fiks-maskinporten-dotnet

MIT license Nuget GitHub issues

.net core library for maskinporten authorization through ID-porten

Installation

Install KS.Fiks.Maskinporten.Client nuget package in your .net project.

Example

Setup configuration

var maskinportenConfig = new MaskinportenClientConfiguration(
    audience: @"https://oidc-ver2.difi.no/idporten-oidc-provider/", // ID-porten audience path
    tokenEndpoint: @"https://oidc-ver2.difi.no/idporten-oidc-provider/token", // ID-porten token path
    issuer: @"oidc_ks_test",  // Issuer name
    numberOfSecondsLeftBeforeExpire: 10, // The token will be refreshed 10 seconds before it expires
    certificate: /* virksomhetssertifikat as a X509Certificate2  */);

Create instance of MaskinportenClient

var maskinportenClient = new MaskinportenClient(maskinportenConfig);

Get access token

var scope = "ks:fiks" // Scope for access token
var accessToken = await maskinportenClient.GetAccessToken(scope);

Send request using access token

var httpClient = new HttpClient();
using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, /* api uri */))
{
  // Set authorization header with maskinporten access token
  requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Token);
    
  /* Set other headers. Integration id and password etc.*/ 
  
  // Send message
  var response = await httpClient.SendAsync(requestMessage);

  /* Handle response */
}
You can’t perform that action at this time.