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

DevToys–A swiss army knife for developers

As a developer there are a lot of small tasks you need to do as part of your coding, debugging and testing activities.  DevToys is an offline windows app that tries to help you with these tasks. Instead of using different websites you get a fully offline experience offering help for a large list of tasks. Many tools are available. Here is the current list: Converters JSON <> YAML Timestamp Number Base Cron Parser Encoders / Decoders HTML URL Base64 Text & Image GZip JWT Decoder Formatters JSON SQL XML Generators Hash (MD5, SHA1, SHA256, SHA512) UUID 1 and 4 Lorem Ipsum Checksum Text Escape / Unescape Inspector & Case Converter Regex Tester Text Comparer XML Validator Markdown Preview Graphic Color B

Help! I accidently enabled HSTS–on localhost

I ran into an issue after accidently enabling HSTS for a website on localhost. This was not an issue for the original website that was running in IIS and had a certificate configured. But when I tried to run an Angular app a little bit later on http://localhost:4200 the browser redirected me immediately to https://localhost . Whoops! That was not what I wanted in this case. To fix it, you need to go the network settings of your browser, there are available at: chrome://net-internals/#hsts edge://net-internals/#hsts brave://net-internals/#hsts Enter ‘localhost’ in the domain textbox under the Delete domain security policies section and hit Delete . That should do the trick…

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.