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.

Podman– Command execution failed with exit code 125

After updating WSL on one of the developer machines, Podman failed to work. When we took a look through Podman Desktop, we noticed that Podman had stopped running and returned the following error message: Error: Command execution failed with exit code 125 Here are the steps we tried to fix the issue: We started by running podman info to get some extra details on what could be wrong: >podman info OS: windows/amd64 provider: wsl version: 5.3.1 Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM Error: unable to connect to Podman socket: failed to connect: dial tcp 127.0.0.1:2655: connectex: No connection could be made because the target machine actively refused it. That makes sense as the podman VM was not running. Let’s check the VM: >podman machine list NAME         ...

Cleaner switch expressions with pattern matching in C#

Ever find yourself mapping multiple string values to the same result? Being a C# developer for a long time, I sometimes forget that the C# has evolved so I still dare to chain case labels or reach for a dictionary. Of course with pattern matching this is no longer necessary. With pattern matching, you can express things inline, declaratively, and with zero repetition. A small example I was working on a small script that should invoke different actions depending on the environment. As our developers were using different variations for the same environment e.g.  "tst" alongside "test" , "prd" alongside "prod" .  We asked to streamline this a long time ago, but as these things happen, we still see variations in the wild. This brought me to the following code that is a perfect example for pattern matching: The or keyword here is a logical pattern combinator , not a boolean operator. It matches if either of the specified pattern...