Skip to content

.Net Core library to load and parse metadata from ADFS 3.0 metadata endpoint

License

Notifications You must be signed in to change notification settings

drwatson1/adfs-metadata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ADFS Metadata Parser

NuGet Status

It is a small C# library to load and parse ADFS metadata. Parser was tested on ADFS 3.0.

Features

  • Asynchronous loading a metadata directly from ADFS 3.0 server
  • Caching metadata between calls
  • Ability to reload if needed
  • DI-Container friendly
  • Supported metadata
    • Federation server identity
    • Signing certificate

Installing

Install-Package DrWatson.Adfs.Metadata

Usage

AdfsMetadataService svc = new AdfsMetadataLoader("https://fs.example.com");
// Exception can be thrown
var metadata = await svc.Get();

// Subsequent  calls will return result from cache
metadata = await svc.Get();

// Now we can use metadata as:
string IdP = metadata.Identity;
string stringSigningCert = metadata.SigningCertificateString;

// Or get certificate with the extension method:
X509Certificate2 signingCert = metadata.GetSigningCertificate();

// Start reloading
svc.Invalidate();

// Now we have a new metadata
metadata = await svc.Get();

You can get more control over the loading metadata document if you'll use another constructor for this:

AdfsMetadataService svc = new AdfsMetadataLoader(() =>
{
    return new HttpClient().GetStringAsync(
        "https://fs.example.com/FederationMetadata/2007-06/FederationMetadata.xml"
    );
});

Inside the ASP.Net Core application you can use extension methods to register the loader as a service:

services.AddAdfsMetadata("https://fs.example.com");

Or:

services.AddAdfsMetadata(() =>
{
    return new HttpClient().GetStringAsync(
        "https://fs.example.com/FederationMetadata/2007-06/FederationMetadata.xml"
    );
});