Skip to main content

ADFS Claim rules

ADFS has the concept of claim rules which allow you to enumerate, add, delete, and modify claims. This is useful when you want for example introduce extra claims (based on data in a database or AD) or transform incoming claims.

Although the available documentation is already helpful, I still find it a challenge to write my own claim rules. So therefore this post…

Claim rule components

To start a claim rule consists of 2 parts, separated by the “=>” operator:

  • An optional(!) condition

  • An issuance statement

So both these rules are correct:

Rule #1:

=> issue(type = "https://test/role", value = "employee");

Rule #2:

c:[type == "https://test/employee", value == "true"] => issue(type = "https://test/role", value = "employee")

The first rule will always generate a new outgoing claim of type https://test/role. The second rule will only generate a new outgoing claim of type https://test/role when an incoming claim of type https://test/employee with a value true is found.

Remark: It is also possible to generate a new claim in the incoming claim set, If you want to know more, check the documentation here.

Conditions

Conditions can come in multiple forms. In the example above I used a single-expression condition but it is also possible to combine multiple conditions using the &&:

c1:[type == "https://test/name"] && c2:[type == "https://test/email"] => issue(claim = c1);

Scenarios

Now that I have explained the basics, let’s look at some typical scenario’s I use the most:

Scenario 1 – Create a new claim

Let’s start simple by creating a new claim:

=> issue(Type = http://schemas.example.be/iam/claims/authorized, Value = "True");

Scenario 2 – Create a new claim from an existing one

We can also create a new claim based on values from an existing claim:

c1:[Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"]
  => issue(Type = http://schemas.example.be/iam/claims/fullname, Value = c1.Value);

Scenario 3 -  Pass an existing claim

By default no claims are automatically passed. If you want to pass a claim, you can use the following rule:

c:[Type == "http://schemas.example.be/iam/claims/personid"]
  => issue(claim = c);

Scenario 4 – Check the attribute store

ADFS can link to one or more attribute stores that can be queried for extra data. For example, we can query a database based on an incoming claims value:

c:[Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"]
  => issue(store = "IAMDB", types = (http://schemas.example.be/iam/claims/authorized, http://schemas.example.be/iam/claims/FullName"), query = "exec IsAuthorized @UserName={0}, @Application=Example'", param = c.Value);

Rule order

It is important to understand that the rules are executed in a specific order. So if one rule depends on the output of a previous rule, make sure that the order is correctly set.

More information

The Role of the Claim Rule Language | Microsoft Learn

Understanding Claim Rule Language in AD FS 2.0 & Higher - TechNet Articles - United States (English) - TechNet Wiki (microsoft.com)

Popular posts from this blog

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.

Kubernetes–Limit your environmental impact

Reducing the carbon footprint and CO2 emission of our (cloud) workloads, is a responsibility of all of us. If you are running a Kubernetes cluster, have a look at Kube-Green . kube-green is a simple Kubernetes operator that automatically shuts down (some of) your pods when you don't need them. A single pod produces about 11 Kg CO2eq per year( here the calculation). Reason enough to give it a try! Installing kube-green in your cluster The easiest way to install the operator in your cluster is through kubectl. We first need to install a cert-manager: kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.5/cert-manager.yaml Remark: Wait a minute before you continue as it can take some time before the cert-manager is up & running inside your cluster. Now we can install the kube-green operator: kubectl apply -f https://github.com/kube-green/kube-green/releases/latest/download/kube-green.yaml Now in the namespace where we want t...

.NET 8–Keyed/Named Services

A feature that a lot of IoC container libraries support but that was missing in the default DI container provided by Microsoft is the support for Keyed or Named Services. This feature allows you to register the same type multiple times using different names, allowing you to resolve a specific instance based on the circumstances. Although there is some controversy if supporting this feature is a good idea or not, it certainly can be handy. To support this feature a new interface IKeyedServiceProvider got introduced in .NET 8 providing 2 new methods on our ServiceProvider instance: object? GetKeyedService(Type serviceType, object? serviceKey); object GetRequiredKeyedService(Type serviceType, object? serviceKey); To use it, we need to register our service using one of the new extension methods: Resolving the service can be done either through the FromKeyedServices attribute: or by injecting the IKeyedServiceProvider interface and calling the GetRequiredKeyedServic...