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

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         ...

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.

VS Code Planning mode

After the introduction of Plan mode in Visual Studio , it now also found its way into VS Code. Planning mode, or as I like to call it 'Hannibal mode', extends GitHub Copilot's Agent Mode capabilities to handle larger, multi-step coding tasks with a structured approach. Instead of jumping straight into code generation, Planning mode creates a detailed execution plan. If you want more details, have a look at my previous post . Putting plan mode into action VS Code takes a different approach compared to Visual Studio when using plan mode. Instead of a configuration setting that you can activate but have limited control over, planning is available as a separate chat mode/agent: I like this approach better than how Visual Studio does it as you have explicit control when plan mode is activated. Instead of immediately diving into execution, the plan agent creates a plan and asks some follow up questions: You can further edit the plan by clicking on ‘Open in Editor’: ...