<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Pietro's Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/piameruo/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/piameruo/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 03:31:15 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>ADFS OpenID Connect custom ID_token</title>
      <link>https://docs.microsoft.com/archive/blogs/piameruo/custom_idtoken</link>
      <pubDate>Sun, 22 Oct 2017 10:13:50 GMT</pubDate>
      <dc:creator><![CDATA[Pietro Ameruoso]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/piameruo/?p=1</guid>
      <description><![CDATA[Hi Guys! In this article I will show you in detail what is necessary to do to generate custom...]]></description>
      <content:encoded><![CDATA[Hi Guys! In this article I will show you in detail what is necessary to do to generate custom ID_tokens Using ADFS 4.0 and OpenID Connect.

If you would like to reproduce this lab I'm going to use exactly the same environment described at the following article:

https://docs.microsoft.com/en-us/windows-server/identity/ad-fs/development/enabling-openid-connect-with-ad-fs

In my environment I extended the users class attributes too to push them in my id_token via claims.

Please take note of the client_id and shared secret generated during the setup process of the lab.

Make sure that the <strong>Client_ID</strong> of the server application and the <strong>Relying party identifier </strong>of the web api are matching.<img width="478" height="541" class="alignnone wp-image-55 " style="height: 535px;text-align: left;color: #333333;text-indent: 0px;letter-spacing: normal;font-size: 16px;font-style: normal;font-variant: normal;font-weight: 400;text-decoration: none;max-width: 1169.34px;background-color: transparent" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/10/217.png" />  <img width="478" height="538" class="alignnone wp-image-46 " style="height: 536px;text-align: left;color: #333333;text-indent: 0px;letter-spacing: normal;font-size: 16px;font-style: normal;font-variant: normal;font-weight: 400;text-decoration: none;max-width: 1169.34px;background-color: transparent" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/10/111.png" />

&nbsp;

Next in the web api properties select Client Permission and make sure that <strong>“allatclaims”</strong> is enabled.

<img width="477" height="533" class="alignnone wp-image-65 " alt="" src="https://msdnshared.blob.core.windows.net/media/2017/10/312.png" />

Now for reproducing the authentication using openid I used Postman. You can use Fiddler too, they can do the same things.

Parameters recap:

Client_id = d93b0bb3-3e84-48fa-8ad1-4813921d125d

Redirect_uri = <a href="https://localhost:44320">https://localhost:44320</a>

Response_type= code

Scope = openid

Response_mode = form_post

<strong>Even if response_mode is an optional parameter we need to declare it as “form_post”</strong><strong> to get the full id_token. In this way we tell the browser to use the POST method for passing the authorization code to ADFS!</strong>

This will be my authorization request in Postman:

<a href="https://login.domain.it/adfs/oauth2/authorize/?client_id=d93b0bb3-3e84-48fa-8ad1-4813921d125d&amp;redirect_uri=https://localhost:44320&amp;response_mode=form_post&amp;response_type=code&amp;scope=openid+profile&amp;nonce=nonce">https://myadfsfqn.com/adfs/oauth2/authorize/?client_id=d93b0bb3-3e84-48fa-8ad1-4813921d125d&amp;redirect_uri=https://localhost:44320&amp;response_mode=form_post&amp;response_type=code&amp;scope=openid+profile&amp;nonce=nonce</a>

<span>By pressing send I will obtain my authorization code (copy and put it somewhere in notepad).</span>

<img width="2028" height="749" class="alignnone wp-image-75 size-full" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/10/411.png" />

&nbsp;

Next we need to POST the authorization code to the ADFS token endpoint.

<img width="1985" height="419" class="alignnone wp-image-76 size-full" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/10/52.png" />

As you can see I created a new tab in Postman and I selected the POST method.

Than I selected x-www-form-urlencoded and added the following values:

Grant_type = authorization_code

Code = the authorization code from the previous request

Redirect_uri = <a href="https://localhost:44320">https://localhost:44320</a>

Client_id = d93b0bb3-3e84-48fa-8ad1-4813921d125d

Scope = openid

Client_secret = the client secret obtained from the setup process

Next I click on send to obtain my tokens:

<img width="2069" height="624" class="alignnone wp-image-126 size-full" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/10/104.png" />

If we copy the id_token value and paste it on jwt.io we are able to decode and see our custom id_token with the custom claims.

<img width="493" height="960" class="aligncenter wp-image-135 " alt="" src="https://msdnshared.blob.core.windows.net/media/2017/10/7-12_17_59-23-10-2017-526x1024.png" />

Here you can see my custom claims. (codfisc is a custom attribute that I added to the user class in AD).

<img width="780" height="616" class="aligncenter wp-image-136 " alt="" src="https://msdnshared.blob.core.windows.net/media/2017/10/8-12_18_55-23-10-2017.png" />

Hope that this post helps you implementing custom ID_tokens for your web api applications!

&nbsp;

&nbsp;]]></content:encoded>
    </item>
  </channel>
</rss>