<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Pedro Félix&#039;s shared memory</title>
	<atom:link href="https://pfelix.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://pfelix.wordpress.com</link>
	<description>Conjectures on software</description>
	<lastBuildDate>Mon, 15 Jun 2020 21:52:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<site xmlns="com-wordpress:feed-additions:1">3662583</site><cloud domain='pfelix.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>https://s0.wp.com/i/buttonw-com.png</url>
		<title>Pedro Félix&#039;s shared memory</title>
		<link>https://pfelix.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="https://pfelix.wordpress.com/osd.xml" title="Pedro Félix&#039;s shared memory" />
	<atom:link rel='hub' href='https://pfelix.wordpress.com/?pushpress=hub'/>
	<item>
		<title>Reactive streams: a play in multiple acts</title>
		<link>https://pfelix.wordpress.com/2020/02/04/reactive-streams-a-play-in-multiple-acts/</link>
					<comments>https://pfelix.wordpress.com/2020/02/04/reactive-streams-a-play-in-multiple-acts/#respond</comments>
		
		<dc:creator><![CDATA[pedrofelix]]></dc:creator>
		<pubDate>Tue, 04 Feb 2020 15:17:06 +0000</pubDate>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[reactive]]></category>
		<guid isPermaLink="false">http://blog.pedrofelix.org/?p=1784</guid>

					<description><![CDATA[One of the most important things to understand when working with reactive streams is that things happen in different moments. In the following, we describe this play in three different acts: assemble, subscription, and data flow To start, let&#8217;s considerer the following code excerpt, which uses Project Reactor&#8217;s reactive streams implementation. Act 1: assemble The [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p class="has-text-align-left">One of the most important things to understand when working with reactive streams is that <em>things</em> happen in different <em>moments</em>. In the following, we describe this play in three different acts: assemble, subscription, and data flow</p>



<p>To start, let&#8217;s considerer the following code excerpt, which uses <a href="https://projectreactor.io">Project Reactor&#8217;s </a>reactive streams implementation. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: java; title: ; notranslate">
    @Test
    fun `a play in multiple acts`() {
        val done = CountDownLatch(2)

        log.info(&quot;Creating the mono, i.e., the processing pipeline&quot;)
        val mono: Mono&lt;Int&gt; = Mono.create&lt;Int&gt; {
                log.info(&quot;Mono.create callback called, emitting value&quot;)
                it.success(42)
            }
            .map {
                log.info(&quot;map: multiplying value by 2&quot;)
                it * 2
            }
            .delayElement(Duration.ofMillis(1000))
            .map {
                log.info(&quot;map: dividing value by 2&quot;)
                it / 2
            }

        log.info(&quot;Mono created, resting for a bit...&quot;)
        Thread.sleep(1000)
        log.info(&quot;Now going to subscribe to the mono&quot;)

        log.info(&quot;subscribing to mono on main thread&quot;)
        mono.subscribe {
            log.info(&quot;mono.subscribe called with {}&quot;, it)
            done.countDown()
        }
        log.info(&quot;subscription done&quot;)

        thread(name = &quot;my-thread&quot;) {
            log.info(&quot;subscribing to mono on a different thread&quot;)
            mono.subscribe {
                log.info(&quot;mono.subscribe called with {}&quot;, it)
                done.countDown()
            }
            log.info(&quot;subscription done&quot;)
        }


        // waiting for subscribers to receive value before ending the test
        done.await()
    }
</pre></div>


<h2 class="wp-block-heading">Act 1: assemble</h2>



<p>The first thing this example does is create a <code><a href="https://projectreactor.io/docs/core/release/api/">Mono&lt;Int&gt;</a></code> and store it in the <code>mono</code> value (a <a href="https://projectreactor.io/docs/core/release/api/">Mono&lt;T&gt;</a> is a special kind of <em>publisher</em> that completes successfully by emitting a single element, or completes with an error). This is done by </p>



<ul class="wp-block-list"><li>First, creating a <code>Mono&lt;Int&gt;</code> using the <code>create</code> static function.</li><li>Using the <code>map</code> operator to obtain a second <em>mono</em> that will emit the value from the first one, multiplied by 2.</li><li>Using the <code>delayElement</code> operator to obtain a third <em>mono</em> that will emit the element after a 1000 millisecond delay.</li><li>Finally, using the <code>map</code> operator again to create a final <em>mono</em> that will emit the value divided by 2.</li></ul>



<p>The <em>assemble act</em> uses <a href="http://reactivex.io/documentation/operators.html">reactive operators</a> (e.g. <code>map</code>, <code>delayElement</code>) to build a data processing pipeline, represented in the following figure.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img width="121" height="266" data-attachment-id="1799" data-permalink="https://pfelix.wordpress.com/pipeline/" data-orig-file="https://pfelix.wordpress.com/wp-content/uploads/2020/02/pipeline.png" data-orig-size="121,266" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="pipeline" data-image-description="" data-image-caption="" data-medium-file="https://pfelix.wordpress.com/wp-content/uploads/2020/02/pipeline.png?w=121" data-large-file="https://pfelix.wordpress.com/wp-content/uploads/2020/02/pipeline.png?w=121" src="https://pfelix.wordpress.com/wp-content/uploads/2020/02/pipeline.png?w=121" alt="" class="wp-image-1799" /></figure></div>



<p>Note that during this phase no data is being transformed or emitted, only the <em>pipeline</em> is being assembled. As an example, the call to the <code>map</code> method does not immediately perform a data transform. Instead, it just returns a new mono that will emit the transformed value sometime in the future. In other words, nothing happens until there is a subscription to the mono (at least for <em>cold</em> publishers, but that is the subject of another post).</p>



<h2 class="wp-block-heading">Act 2: subscription</h2>



<p>After the processing pipeline is built, then we can pass on to the second act: the subscription. In this phase, subscribers that want access the data emitted by the mono, call the <code>subscribe</code> method, passing in a callback function.</p>



<p>In our example, we perform the subscription on the main thread and on a newly created thread. The end goal is to illustrate that:</p>



<ul class="wp-block-list"><li>The same <em>mono</em> can be subscribed multiple times.</li><li>The subscription can perfectly happen on a different thread from the one where the mono was created.</li></ul>



<p>The following log output shows some interesting results.</p>



<pre class="wp-block-code"><code>15:29:39.616 &#091;      main] INFO  - Creating the mono, i.e., the processing pipeline
15:29:39.692 &#091;      main] INFO  - Mono created, resting for a bit...
15:29:40.692 &#091;      main] INFO  - Now going to subscribe to the mono

15:29:40.693 &#091;      main] INFO  - subscribing to mono on main thread
15:29:40.700 &#091;      main] INFO  - Mono.create callback called, emitting value
15:29:40.701 &#091;      main] INFO  - map: multiplying value by 2
15:29:40.703 &#091;      main] INFO  - subscription done

15:29:40.705 &#091; my-thread] INFO  - subscribing to mono on a different thread
15:29:40.707 &#091; my-thread] INFO  - Mono.create callback called, emitting value
15:29:40.707 &#091; my-thread] INFO  - map: multiplying value by 2
15:29:40.707 &#091; my-thread] INFO  - subscription done

15:29:41.704 &#091;parallel-1] INFO  - map: dividing value by 2
15:29:41.707 &#091;parallel-2] INFO  - map: dividing value by 2
15:29:41.707 &#091;parallel-1] INFO  - mono.subscribe called with 42
15:29:41.708 &#091;parallel-2] INFO  - mono.subscribe called with 42</code></pre>



<ul class="wp-block-list"><li>The callback function passed into the <code>Mono.create</code> is only called when there is a subscription. In addition, it is called once per subscription, in the same thread where the subscription is performed and before the subscribe method even returns.</li><li>Since the callback immediately emits a value (<code>it.success(42)</code>) when called, then the next processing phase in the pipeline (i.e. the one defined by the first <code>map</code>) is also immediately called (see <code>map: multiplying value by 2</code>), also before the <code>subscribe</code> method returns.</li></ul>



<h2 class="wp-block-heading">Act 3: data flow</h2>



<p>As we saw in the previous log, the flow of data through the pipeline is only started when there is a subscription. Namely, both the create callback and the first processing phase happened synchronously with the subscription (i.e. at the same time and in the same thread).<br>However, the second map processing phase (see <code>map: dividing value by 2</code>) and the subscription callback are performed on a different thread, after approximately one second. That happens because between the first and the second map there is a <code>delayElement</code>: the value is only emitted into the second <em>map phase</em> one second after being produced by the first <em>map phase</em>. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img width="481" height="361" data-attachment-id="1800" data-permalink="https://pfelix.wordpress.com/flow/" data-orig-file="https://pfelix.wordpress.com/wp-content/uploads/2020/02/flow.png" data-orig-size="481,361" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="flow" data-image-description="" data-image-caption="" data-medium-file="https://pfelix.wordpress.com/wp-content/uploads/2020/02/flow.png?w=300" data-large-file="https://pfelix.wordpress.com/wp-content/uploads/2020/02/flow.png?w=481" src="https://pfelix.wordpress.com/wp-content/uploads/2020/02/flow.png?w=481" alt="" class="wp-image-1800" srcset="https://pfelix.wordpress.com/wp-content/uploads/2020/02/flow.png 481w, https://pfelix.wordpress.com/wp-content/uploads/2020/02/flow.png?w=150 150w, https://pfelix.wordpress.com/wp-content/uploads/2020/02/flow.png?w=300 300w" sizes="(max-width: 481px) 100vw, 481px" /></figure></div>



<p>This is an example of an asynchronous processing phase. Since a fundamental characteristic of reactive streams is that there should be no blocking, the thread that performs the first map is released and the second map is performed on a thread managed by Reactor, only when the delay period elapses.</p>



<p>The flow of data through the pipeline starts when there is a subscription but it doesn&#8217;t end there. Namely, if there are asynchronous processing phases in the pipeline, the flow can pause (without blocking) and resume when some asynchronous event happens (e.g. a time period elapses, a message from a remote system is received). That is, the flow can be divided into multiple segments, with non-blocking pauses between them.</p>



<h2 class="wp-block-heading">Summary</h2>



<ul class="wp-block-list"><li>There are at least three different moments (the <em>acts</em>) associated with reactive streams<ul><li>The pipeline assembly.</li><li>The subscription.</li><li>The data flow, through the pipeline.</li></ul></li><li>Nothing happens until there is a subscription.</li><li>Data flow can happen partially or totally during the subscription.</li><li>Data flow can be divided into multiple segments, with non-blocking pauses between them (e.g. time delay, waiting for external system event).</li><li>On a <em>cold</em> publisher, there is a flow of data per each subscription. In the case of a mono, that flow will be comprised of a single element (at most).</li></ul>



<p>The source code is available on the <a href="https://github.com/pmhsfelix/webflux-with-kotlin-by-example">webflux-with-kotlin-by-example</a> repository.</p>



<p>HTH</p>
]]></content:encoded>
					
					<wfw:commentRss>https://pfelix.wordpress.com/2020/02/04/reactive-streams-a-play-in-multiple-acts/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1784</post-id>
		<media:content url="https://2.gravatar.com/avatar/2f120f7985f2306ba6ef1b49b657ecb30c5c6517257d495d5d9c574b634c2eba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pedrofelix</media:title>
		</media:content>

		<media:content url="https://pfelix.wordpress.com/wp-content/uploads/2020/02/pipeline.png?w=121" medium="image" />

		<media:content url="https://pfelix.wordpress.com/wp-content/uploads/2020/02/flow.png?w=481" medium="image" />
	</item>
		<item>
		<title>RFC 8252  and OAuth 2.0 for Native Apps</title>
		<link>https://pfelix.wordpress.com/2017/10/24/rfc-8252-and-oauth-2-0-for-native-apps/</link>
					<comments>https://pfelix.wordpress.com/2017/10/24/rfc-8252-and-oauth-2-0-for-native-apps/#respond</comments>
		
		<dc:creator><![CDATA[pedrofelix]]></dc:creator>
		<pubDate>Tue, 24 Oct 2017 17:21:34 +0000</pubDate>
				<category><![CDATA[Software]]></category>
		<guid isPermaLink="false">http://blog.pedrofelix.org/?p=1767</guid>

					<description><![CDATA[Introduction RFC 8252 &#8211; OAuth 2.0 for Native Apps, published this month by IETF as a Best Current Practice, contains much needed guidance on how to use the OAuth 2.0 framework in native applications. In this post I present a brief summary of the defined best practices. OAuth for native applications When the OAuth 1.0 [&#8230;]]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p><a href="https://tools.ietf.org/html/rfc8252">RFC 8252 &#8211; OAuth 2.0 for Native Apps</a>, published this month by <a href="https://www.ietf.org">IETF</a> as a <em>Best Current Practice</em>, contains much needed guidance on how to use the OAuth 2.0 framework in native applications.<br />
In this post I present a brief summary of the defined best practices.</p>
<h2>OAuth for native applications</h2>
<p>When the OAuth 1.0 protocol was introduced <a href="https://oauth.net/core/1.0/">10 years ago</a>, its main goal was delegated authorization for client applications accessing services on behalf of users.<br />
It was focused on the model &#8220;du jour&#8221;, where client applications were mostly server-side rendered Web sites, interacting with end users via browsers.<br />
For instance, it was assumed that client applications were capable of holding long-term secrets, which is rather easy for servers but not for browser-side applications or native applications running on the user&#8217;s device.</p>
<p><a href="https://tools.ietf.org/html/rfc6749">OAuth 2.0</a>, published on 2012, introduced a <em>framework</em> with multiple different flows, including the support for <em>public clients</em>, that is, clients that don&#8217;t need to hold secrets.<br />
However it was still pretty much focused on classical Web sites and using this framework in the context of native applications was mostly left as an exercise for the reader.<br />
Some of the questions that didn&#8217;t had a clear or straightforward answer were:</p>
<ul>
<li>What is the adequate flow for a native application?</li>
<li>Should a native application be considered a confidential client or a public client?</li>
<li>Assuming an authorization code flow or intrinsic flow, how should the authorization request be performed: via an embedded web view or via the system browser?</li>
<li>How is the authorization response redirected back into the client application, since it isn&#8217;t a server any more? Via listening on a loopback port or using platform specific mechanisms (e.g. Android intents and custom URI schemes)?</li>
<li>What&#8217;s the proper way for avoiding code or token leakage into malicious applications also installed in the user&#8217;s device?</li>
</ul>
<p>The first major guidance to these questions came with <a href="https://tools.ietf.org/html/rfc7636">RFC 7636 &#8211; Proof Key for Code Exchange by OAuth Public Clients</a>, published in 2015.<br />
This document defines a way to use the authorization code flow with public clients, i.e. adequate to native applications, protected against the interception of the authorization code by another application (e.g. malicious applications installed in the same user device).<br />
The problem that it addresses as well as the proposed solutions are described on a previous post: <a href="https://blog.pedrofelix.org/2016/02/15/oauth-2-0-and-pkce/">OAuth 2.0 and PKCE</a>.</p>
<p>The recently published <a href="https://tools.ietf.org/html/rfc8252">RFC 8252 &#8211; OAuth 2.0 for Native Apps</a> (October 2017) builds upon RFC 7636 and defines a set of best practices for when using OAuth 2.0 on native applications, with emphasis on the user-agent integration aspects.</p>
<p>In summary, it defines the following best practices:</p>
<ul>
<li>A native client application must be a <em>public client</em>, except if using <em>dynamic client registration</em> (<a href="https://tools.ietf.org/html/rfc7591">RFC7591</a>) to provision per device unique clients, where each application installation has an set of secret credentials) &#8211; <a href="https://tools.ietf.org/html/rfc8252#section-8.4">section 8.4</a>.</p>
</li>
<li>
<p>The client application should use the authorization code grant flow with PKCE (<a href="https://tools.ietf.org/html/rfc7636">RFC 7636 &#8211; Proof Key for Code Exchange by OAuth Public Clients</a>), instead of the implicit flow, namely because the later does not support the protection provided by PKCE &#8211; <a href="https://tools.ietf.org/html/rfc8252#section-8.2">section 8.2</a>.</p>
</li>
<li>
<p>The application should use an external user-agent, such as the system browser, instead of an embedded user-agent such as a web view &#8211; <a href="https://tools.ietf.org/html/rfc8252#section-4">section 4</a>.</p>
<ul>
<li>An application using a web view can control everything that happens inside it, namely access the user&#8217;s credentials when they are inserted on it.<br />
Using an external user-agent isolates the user credentials from the client application, which is one of the OAuth 2.0 original goals.</p>
</li>
<li>
<p>Using the system-browser can also provide a kind of Single Sign-On &#8211; users delegating access to <em>multiple</em> applications using the <em>same</em> authorization server (or delegated identity provider) only have to authenticate once because the session artifacts (e.g. cookies) will still be available.</p>
</li>
<li>
<p>To avoid switching out of the application into the external user-agent, which may not provide a good user experience, some platforms support &#8220;in-app browser tabs&#8221; where the user agent <em>seems</em> to be embedded into the application, while supporting full data isolation &#8211; iOS <a href="https://developer.apple.com/documentation/safariservices/sfauthenticationsession">SFAuthenticationSession</a> or Android&#8217;s <a href="https://developer.chrome.com/multidevice/android/customtabs">Chrome Custom Tabs</a>.</p>
</li>
</ul>
</li>
<li>
<p>The authorization request should use one of the chosen user-agent mechanism, by providing it with the URI for the <a href="https://tools.ietf.org/html/rfc6749#section-3.1">authorization endpoint</a> with the embedded request on it.</p>
</li>
<li>
<p>The redirect back to the application can use one of multiple techniques.</p>
<ul>
<li>Use a redirect endpoint (e.g. <code>com.example.myapp:/oauth2/redirect</code>) with a private scheme (e.g. <code>com.example.myapp</code>) that <em>points</em> to the application.<br />
Android&#8217;s <a href="https://developer.android.com/training/basics/intents/filters.html">implicit intents</a> are an example of a mechanism allowing this.<br />
When using this technique, the custom URI scheme must be the reversal of a domain name under the application&#8217;s control (e.g. <code>com.example.myapp</code> if the  <code>myapp.example.com</code> name is controlled by the application&#8217;s author) &#8211; <a href="https://tools.ietf.org/html/rfc8252#section-7.1">section 7.1</a>.</p>
</li>
<li>
<p>Another option is to use a <em>claimed</em> HTTPS redirect URI, which is a feature provided by some platforms (e.g. <a href="https://developer.android.com/training/app-links/index.html">Android&#8217;s App Links</a>) where a request to a claimed URI triggers a call into the application instead of a regular HTTP request. This is considered to be the preferred method &#8211; <a href="https://tools.ietf.org/html/rfc8252#section-7.2"> section 7.2</a>.</p>
</li>
<li>
<p>As a final option, the redirect can be performed by having the application listening on the loopback interface (<code>127.0.0.1</code> or <code>::1</code>).</p>
</li>
</ul>
</li>
</ul>
<p>To illustrate these best practices, the following diagram represents an end-to-end OAuth 2.0 flow on a native application</p>
<p><img data-attachment-id="1769" data-permalink="https://pfelix.wordpress.com/2017/10/24/rfc-8252-and-oauth-2-0-for-native-apps/native-auth/" data-orig-file="https://pfelix.wordpress.com/wp-content/uploads/2017/10/native-auth.png" data-orig-size="724,559" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="native.auth" data-image-description="" data-image-caption="" data-medium-file="https://pfelix.wordpress.com/wp-content/uploads/2017/10/native-auth.png?w=300" data-large-file="https://pfelix.wordpress.com/wp-content/uploads/2017/10/native-auth.png?w=625" src="https://pfelix.wordpress.com/wp-content/uploads/2017/10/native-auth.png" alt="native.auth" width="724" height="559" class="alignnone size-full wp-image-1769" srcset="https://pfelix.wordpress.com/wp-content/uploads/2017/10/native-auth.png 724w, https://pfelix.wordpress.com/wp-content/uploads/2017/10/native-auth.png?w=150&amp;h=116 150w, https://pfelix.wordpress.com/wp-content/uploads/2017/10/native-auth.png?w=300&amp;h=232 300w" sizes="(max-width: 724px) 100vw, 724px" /></p>
<ul>
<li>On step 1, the application invokes the external user-agent, using a platform specific mechanism, and passing in the authorization URI with the embedded authorization request.</p>
</li>
<li>
<p>As a consequence, on step 2, the external user-agent is activated and does a HTTP request to the authorization endpoint using the provided URI.</p>
</li>
<li>
<p>The response to step 2 depends on the concrete authorization endpoint and is not defined by the OAuth specifications.<br />
A common pattern is for the response to be a redirect to a login page, followed by a consent page.</p>
</li>
<li>
<p>On step 3, after ending the direct user interaction, the authorization endpoint produces a HTTP response with the authorization response embedded inside (e.g. 302 status code with the authorization response URI in the <code>Location</code> header).</p>
</li>
<li>
<p>On step 4, the user-agent reacts to this response by processing the redirect URI.<br />
If using a private scheme or a claimed redirect URI, the user-agent uses a platform specific inter process communication mechanism to deliver the authorization response to the application (e.g. Android&#8217;s intents).<br />
If using <code>localhost</code> as the redirect URI host, the user-agent does a regular HTTP requests to the loopback interface, which is being listened by the application, thereby providing the authorization response to it.</p>
</li>
<li>
<p>On steps 5 and 6, the application exchanges the authorization code for the access and refresh tokens, using a straightforward token request.<br />
This interaction is done directly between the client and the token endpoint, without going through the user-agent, since no user interaction is needed (<a href="http://chimera.labs.oreilly.com/books/1234000001708/ch16.html#_front_channel_versus_back_channel">back-channel vs. front-channel</a>).<br />
Since the client is public, this interaction is not authenticated (i.e. does not include any client application credentials).<br />
Due to this anonymous characteristic and to protect against code hijack, the code_verifier` parameter from the PKCE extension must be added to the token request.</p>
</li>
<li>
<p>Finally, on step 7, the application can use the resource server on the user&#8217;s behalf, by adding the access token to the <code>Authorization</code> header.</p>
</li>
</ul>
<p>The <code>AppAuth</code> libraries for <a href="https://github.com/openid/AppAuth-iOS">iOS</a> and <a href="https://github.com/openid/AppAuth-Android">Android</a> already follows these best practices.</p>
<p>I hope this brief summary helps.<br />
As always, questions, comments, and suggestions are highly appreciated.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://pfelix.wordpress.com/2017/10/24/rfc-8252-and-oauth-2-0-for-native-apps/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1767</post-id>
		<media:content url="https://2.gravatar.com/avatar/2f120f7985f2306ba6ef1b49b657ecb30c5c6517257d495d5d9c574b634c2eba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pedrofelix</media:title>
		</media:content>

		<media:content url="https://pfelix.wordpress.com/wp-content/uploads/2017/10/native-auth.png" medium="image">
			<media:title type="html">native.auth</media:title>
		</media:content>
	</item>
		<item>
		<title>Accessing the HTTP Context on ASP.NET Core</title>
		<link>https://pfelix.wordpress.com/2016/11/01/accessing-the-http-context-on-asp-net-core/</link>
					<comments>https://pfelix.wordpress.com/2016/11/01/accessing-the-http-context-on-asp-net-core/#comments</comments>
		
		<dc:creator><![CDATA[pedrofelix]]></dc:creator>
		<pubDate>Tue, 01 Nov 2016 12:00:44 +0000</pubDate>
				<category><![CDATA[Software]]></category>
		<guid isPermaLink="false">http://pfelix.wordpress.com/?p=1698</guid>

					<description><![CDATA[TL;DR On ASP.NET Core, the access to the request context can be done via the new IHttpContextAccessor interface, which provides a HttpContext property with this information. The IHttpContextAccessor is obtained via dependency injection or directly from the service locator. However, it requires an explicit service collection registration, mapping the IHttpContextInterface to the HttpContextAccessor concrete class, [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>TL;DR</h1>
<p>On ASP.NET Core, the access to the request context can be done via the new <code>IHttpContextAccessor</code> interface, which provides a <code>HttpContext</code> property with this information. The <code>IHttpContextAccessor</code> is obtained via dependency injection or directly from the service locator. However, it requires an explicit  service collection registration, mapping the <code>IHttpContextInterface</code> to the <code>HttpContextAccessor</code> concrete class, with <strong>singleton</strong> scope.</p>
<h1>Not so short version</h1>
<h2>System.Web</h2>
<p>On <em>classical ASP.NET</em>, the current HTTP context, containing both request and response information, can be accessed anywhere via the omnipresent <code>System.Web.HttpContext.Current</code> static property. Internally, this property uses information stored in the <code>CallContext</code> object representing the current call flow. This <code>CallContext</code> is preserved even when the same flow crosses multiple threads, so it can handle <code>async</code> methods.</p>
<h2>ASP.NET Web API</h2>
<p>On ASP.NET Web API, obtaining the current HTTP context without having to flow it explicitly on every call is typically achieved with the help of the dependency injection container.<br />
For instance, <a href="https://autofac.org">Autofac</a> provides the <code>RegisterHttpRequestMessage</code> extension method on the <code>ContainerBuilder</code>, which allows classes to have <code>HttpRequestMessage</code> constructor dependencies.<br />
This extension method configures a delegating handler that registers the input <code>HttpRequestMessage</code> instance into the current lifetime scope.</p>
<h2>ASP.NET Core</h2>
<p>ASP.NET Core uses a different approach. The access to the current context is provided via a <code>IHttpContextAccessor</code> service, containing a single <code>HttpContext</code> property with both a getter and a setter. So, instead of directly injecting the context, the solution is based on injecting an <em>accessor</em> to the context.<br />
This apparently superfluous indirection provides one benefit: the accessor can have singleton scope, meaning that it can be injected into singleton components.<br />
Notice that injecting a per HTTP request dependency, such as the request message, directly into another component is only possible if the component has the same lifetime scope.</p>
<p>In the current ASP.NET Core 1.0.0 implementation, the <code>IHttpContextAccessor</code> service is implemented by the <code>HttpContextAccessor</code> concrete class and <em>must</em> be configured as a <strong>singleton</strong>.<br />
 </p>
<pre class="brush: plain; title: ; notranslate">
public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddSingleton&lt;IHttpContextAccessor, HttpContextAccessor&gt;();
}
</pre>
<p>Notice that this registration is not done by default and must be explicitly performed. If not, any <code>IHttpContextAccessor</code> dependency will result in an activation exception.<br />
On the other hand, no additional configuration is need to capture the context at the beginning of each request, because this is automatically done.</p>
<p>The following implementation details shed some light on this behavior:</p>
<ul>
<li>Each time a new request starts to be handled, a common <code>IHttpContextFactory</code> reference is used to create the <code>HttpContext</code>. This common reference is obtained by the <code>WebHost</code> during startup and used for all requests.</p>
</li>
<li>The used <code>HttpContextFactory</code> concrete implementation is initialized with an optional <code>IHttpContextAccessor</code> implementation. When available, this accessor is assigned with each created context. This means that if any accessor is registered on the services, then it will automatically be used to set all created contexts.</p>
</li>
<li>
<p>How can the same accessor instance hold different contexts, one for each call flow? The answer lies in the <code>HttpContextAccessor</code> concrete implementation and its use of <code>AsyncLocal</code> to store the context separately for each logical call flow. It is this characteristics that allows a <strong>singleton scoped</strong> accessor to provide <strong>request scoped</strong> contexts.</p>
</li>
</ul>
<p>To conclude:</p>
<ul>
<li>
<p>Everywhere the HTTP context is needed, declare an <code>IHttpContextAccessor</code> dependency and use it to fetch the context.</p>
</li>
<li>
<p>Don&#8217;t forget to explicitly register the <code>IHttpContextAccessor</code> interface on the service collection, mapping it to the concrete <code>HttpContextAccessor</code> type.</p>
</li>
<li>
<p>Also, don&#8217;t forget to make this registration with singleton scope.</p>
</li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://pfelix.wordpress.com/2016/11/01/accessing-the-http-context-on-asp-net-core/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1698</post-id>
		<media:content url="https://2.gravatar.com/avatar/2f120f7985f2306ba6ef1b49b657ecb30c5c6517257d495d5d9c574b634c2eba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pedrofelix</media:title>
		</media:content>
	</item>
		<item>
		<title>Should I PUT or should I POST? (Darling you gotta let me know)</title>
		<link>https://pfelix.wordpress.com/2016/10/25/should-i-put-or-should-i-post-darling-you-gotta-let-me-know/</link>
					<comments>https://pfelix.wordpress.com/2016/10/25/should-i-put-or-should-i-post-darling-you-gotta-let-me-know/#respond</comments>
		
		<dc:creator><![CDATA[pedrofelix]]></dc:creator>
		<pubDate>Tue, 25 Oct 2016 04:00:37 +0000</pubDate>
				<category><![CDATA[Software]]></category>
		<guid isPermaLink="false">http://pfelix.wordpress.com/?p=1660</guid>

					<description><![CDATA[(yes, it doesn&#8217;t rhyme however I couldn&#8217;t resist the association) Selecting the proper methods (e.g. GET, POST, PUT, &#8230;) to use when designing HTTP based APIS is typically a subject of much debate, and eventually some bike-shedding. In this post I briefly present the rules that I normally follow when faced with this design task. Don&#8217;t [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>(yes, it doesn&#8217;t rhyme however I couldn&#8217;t resist the <a href="https://en.wikipedia.org/wiki/Should_I_Stay_or_Should_I_Go">association</a>)</p>
<p>Selecting the proper methods (e.g. GET, POST, PUT, &#8230;) to use when designing HTTP based APIS is typically a subject of much debate, and eventually some <a href="https://en.wikipedia.org/wiki/Law_of_triviality">bike-shedding</a>. In this post I briefly present the rules that I normally follow when faced with this design task.</p>
<h2>Don&#8217;t go against the HTTP specification</h2>
<p>First and foremost, make sure the properties of the chosen methods aren&#8217;t violated on the scenario under analysis. The typical offender is using GET for an interaction that requests a state change on the server.<br />
Why is this bad? Because GET is defined to have the <em>safe</em> property, <a href="https://tools.ietf.org/html/rfc7231#section-4.2.1">defined</a> as</p>
<blockquote><p>
  Request methods are considered &#8220;safe&#8221; if their defined semantics are essentially read-only; i.e., the client does not request, and does not expect, any state change on the origin server as a result of applying a safe method to a target resource.
</p></blockquote>
<p>Another example is choosing PUT for requests that aren&#8217;t <em>idempotent</em>, such as appending an item to a collection.<br />
The idempotent property is <a href="https://tools.ietf.org/html/rfc7231#section-4.2.2">defined</a> by RFC 7231 as</p>
<blockquote><p>
  A request method is considered &#8220;idempotent&#8221; if the intended effect on the server of multiple identical requests with that method is the same as the effect for a single such request.
</p></blockquote>
<p>Breaking these properties is harmful because there may exist system components whose correct behavior depends on them being true. An example is a crawler program that freely follows all GET links in a document, assuming that no state change will be performed by these requests, and that ends up changing the system state.</p>
<p>Another example is an intermediary (e.g. reverse proxy) that automatically retries any failed PUT request (e.g. timeout), assuming they are idempotent. If the PUT is appending items to a collection (append is not idempotent), and the first PUT request was successfully performed and only the response message was lost, then the retry will end up adding two replicated items to the collection.</p>
<p>This violation can also have security implications. For instance, most server frameworks don&#8217;t protect GET requests agains CSRF (Cross-Site Request Forgery) attacks because the GET method is not supposed to change state and reads are already protected by the <a href="https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy">same-origin</a> browser policy.</p>
<h2>Take advantage of the method properties</h2>
<p>After ensuring the correctness concerns, i.e., ensuring requests don&#8217;t violate any property of chosen methods, we can revert our analysis and check if there aren&#8217;t any methods that best fit the intended functionality. After having ensured correctness, in this stage our main concern is going to be optimisation.</p>
<p>For instance, if a request defines the complete state for a resource and is idempotent, perhaps a PUT is a better fit than a POST. This is not because a POST will produce incorrect behavior but because using a PUT may induce better system properties. For instance, an intermediary (e.g. reverse proxy or framework middleware) may automatically retry failed requests, and by this provide some fault recovery.</p>
<h2>When nothing else fits, use POST</h2>
<p>Contrary to some HTTP myths, the POST is not solely intended to create resources. In fact, the newer RFC 7231 states</p>
<blockquote><p>
  The POST method requests that the target resource process the representation enclosed in the request according to the resource&#8217;s own specific semantics
</p></blockquote>
<p>The &#8220;according to the resource&#8217;s own specific semantics&#8221; effectively allows us to use POST for requests with <em>any</em> semantics. However the fact that it allows us doesn&#8217;t mean that we always should. Again, if another method (e.g. GET or PUT) best fits the request purpose, not choosing it may mean throwing away interesting properties, such as caching or fault recovery.</p>
<h2>Does my API look RESTful in this method?</h2>
<p>One thing that I always avoid is deciding based on the apparent &#8220;RESTfullness&#8221; of the method &#8211; For instance, <a href="http://roy.gbiv.com/untangled/2009/it-is-okay-to-use-post">an API doesn&#8217;t have to use PUT to be RESTful</a>.</p>
<p>First and foremost we should think in terms of system properties and use HTTP accordingly. That implies:</p>
<ul>
<li>Not violating its rules &#8211; E.g. what can go wrong if I choose PUT for this request?</li>
<li>Taking advantage of its benefits &#8211; E.g. what do I loose if I don&#8217;t choose PUT for this request?</li>
</ul>
<p>I hope this helps. Feedback welcomed.<br />
Cheers.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://pfelix.wordpress.com/2016/10/25/should-i-put-or-should-i-post-darling-you-gotta-let-me-know/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1660</post-id>
		<media:content url="https://2.gravatar.com/avatar/2f120f7985f2306ba6ef1b49b657ecb30c5c6517257d495d5d9c574b634c2eba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pedrofelix</media:title>
		</media:content>
	</item>
		<item>
		<title>Health check APIs, 500 status codes and media types</title>
		<link>https://pfelix.wordpress.com/2016/10/10/health-check-apis-500-status-codes-and-media-types/</link>
					<comments>https://pfelix.wordpress.com/2016/10/10/health-check-apis-500-status-codes-and-media-types/#comments</comments>
		
		<dc:creator><![CDATA[pedrofelix]]></dc:creator>
		<pubDate>Mon, 10 Oct 2016 16:17:30 +0000</pubDate>
				<category><![CDATA[Software]]></category>
		<guid isPermaLink="false">http://pfelix.wordpress.com/?p=1575</guid>

					<description><![CDATA[A status or health check resource (or endpoint, to use the more popular terminology) is a common way for a system to provide an aggregated representation of its operational status. This status representation typically includes a list with the individual system components or health check points and their individual status (e.g. database connectivity, memory usage threshold, deadlocked [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>A status or health check resource (or <em>endpoint</em>, to use the more popular terminology) is a common way for a system to provide an aggregated representation of its operational status. This status representation typically includes a list with the individual system components or health check points and their individual status (e.g. database connectivity, memory usage threshold, deadlocked threads).</p>
<p>For instance, the popular <a href="http://www.dropwizard.io">Dropwizard</a> Java framework already provides an out-of-the-box <a href="http://www.dropwizard.io/1.0.2/docs/manual/core.html#health-checks">health check resource</a>, located by default on the <code>/healthcheck</code> URI of the administration port, for this purpose.</p>
<p>The following is an example of such representation, defined by a JSON object containing a field by each health check verification.</p>
<pre>{
    "deadlocks":{
        "healthy":true
    },
    "database":{
        "healthy":true
    }
}</pre>
<p>Apparently, it is also a common practice for a GET request to these resources to return a 500 status code if any of the internal components reports a problem. For instance, the Dropwizard documentation <a href="http://www.dropwizard.io/0.7.1/docs/manual/core.html#health-checks">states</a></p>
<blockquote><p>
  If all health checks report success, a 200 OK is returned. If any fail, a 500 Internal Server   Error is returned with the error messages and exception stack traces (if an exception was  thrown).
</p></blockquote>
<p>In my opinion, this practice goes against the HTTP status code semantics because the server  was indeed capable of processing the request and producing a valid response with a correct resource state representation, that is, a correct representation of the system status. The fact that this status includes the information of an error does not changes that.</p>
<p>So, why is this incorrect practice used so often? My conjecture has two reasons for it.</p>
<ul>
<li>First, an incomplete knowledge of the HTTP status code semantics that may induce the following reasoning: if the response contains an error then a 500 must be used.</li>
<li> Second, and perhaps more important, because this practice really comes in handy when using external monitoring systems (e.g. nagios) to periodically check these statuses. Since these monitoring systems do not commonly understand the healthcheck representation, namely because each API or framework uses a different one, the easier solution is to rely solely on the status code: 200 if everything is apparently working properly, 500 if something is not ok.</li>
</ul>
<p>Does this difference between a 200 and a 500 matters, or are we just being pedantic here? Well, I do think it really matters: by returning a 500 status code on a correctly handled request, the status resource is hiding errors on its own behaviour. For instance, lets consider the common scenario where the status resource is implemented by a third-party provider. A failure of this provider will be indistinguishable of a failure on the system under checking, because a 500 will be returned in both cases.</p>
<p>This example shows the consequences of the lack of effort on designing and standardizing media types. The availability of a standard media type would allow a many-to-many relation between monitoring systems and health check resources.</p>
<ul>
<li>A health check resource could easily be monitored/queried by any monitoring system.</li>
<li>A monitoring system could easily inspect multiple health check resources, implemented over different technologies.</li>
</ul>
<p>&nbsp;</p>
<p><img loading="lazy" data-attachment-id="1614" data-permalink="https://pfelix.wordpress.com/2016/10/10/health-check-apis-500-status-codes-and-media-types/monitoring-2/" data-orig-file="https://pfelix.wordpress.com/wp-content/uploads/2016/10/monitoring1.png" data-orig-size="646,363" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="monitoring" data-image-description="" data-image-caption="" data-medium-file="https://pfelix.wordpress.com/wp-content/uploads/2016/10/monitoring1.png?w=300" data-large-file="https://pfelix.wordpress.com/wp-content/uploads/2016/10/monitoring1.png?w=625" class=" size-full wp-image-1614 aligncenter" src="https://pfelix.wordpress.com/wp-content/uploads/2016/10/monitoring1.png" alt="monitoring" width="646" height="363" srcset="https://pfelix.wordpress.com/wp-content/uploads/2016/10/monitoring1.png 646w, https://pfelix.wordpress.com/wp-content/uploads/2016/10/monitoring1.png?w=150&amp;h=84 150w, https://pfelix.wordpress.com/wp-content/uploads/2016/10/monitoring1.png?w=300&amp;h=169 300w" sizes="(max-width: 646px) 100vw, 646px" /></p>
<p>Also, by a using a media-type, the monitoring result could be much richer than &#8220;ok&#8221; vs. &#8220;not ok&#8221;.</p>
<p>To conclude with a call-to-action, we really need to create a media type to represent health check or status outcomes, eventually based on an already existing media type:</p>
<ul>
<li>E.g. building upon the &#8220;application/problem+json&#8221; (<a href="https://tools.ietf.org/html/rfc7807">RFC 7807</a>), extended to represent multiple problem status (e.g <a href="https://gist.github.com/pmhsfelix/76dcc1b495000c70ee303cc3dd1e90fa">example</a>).</li>
<li>E.g. building upon the &#8220;<a href="https://github.com/tavis-software/Tavis.Status">application/status+json</a>&#8221; media type proposal.</li>
</ul>
<p>Comments are welcomed.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://pfelix.wordpress.com/2016/10/10/health-check-apis-500-status-codes-and-media-types/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1575</post-id>
		<media:content url="https://2.gravatar.com/avatar/2f120f7985f2306ba6ef1b49b657ecb30c5c6517257d495d5d9c574b634c2eba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pedrofelix</media:title>
		</media:content>

		<media:content url="https://pfelix.wordpress.com/wp-content/uploads/2016/10/monitoring1.png" medium="image">
			<media:title type="html">monitoring</media:title>
		</media:content>
	</item>
		<item>
		<title>On contracts and HTTP APIs</title>
		<link>https://pfelix.wordpress.com/2016/08/27/on-contracts-and-http-apis/</link>
					<comments>https://pfelix.wordpress.com/2016/08/27/on-contracts-and-http-apis/#respond</comments>
		
		<dc:creator><![CDATA[pedrofelix]]></dc:creator>
		<pubDate>Sat, 27 Aug 2016 17:30:13 +0000</pubDate>
				<category><![CDATA[Software]]></category>
		<guid isPermaLink="false">http://pfelix.wordpress.com/?p=1545</guid>

					<description><![CDATA[Reading the twitter conversation started by this tweet https://twitter.com/michaeltecourt/status/769256765624053760 made me put in written words some of the ideas that I have about HTTP APIs, contracts and &#8220;out-of-band&#8221; information. Since it&#8217;s vacations time, I&#8217;ll be brief and incomplete. On any interface, it is impossible to avoid having contracts (i.e. shared &#8220;out-of-band&#8221; information) between provider and [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Reading the twitter conversation started by this tweet</p>
<p><a href="https://twitter.com/michaeltecourt/status/769256765624053760" rel="nofollow">https://twitter.com/michaeltecourt/status/769256765624053760</a></p>
<p>made me put in written words some of the ideas that I have about HTTP APIs, contracts and &#8220;out-of-band&#8221; information.<br />
Since it&#8217;s vacations time, I&#8217;ll be brief and incomplete.</p>
<ul>
<li>On any interface, it is impossible to avoid having contracts (i.e. shared &#8220;out-of-band&#8221; information) between provider and consumer. On a HTTP API, the syntax and semantics of HTTP itself is an example of this shared information. If JSON is used as a base for the representation format, then its syntax and semantics rules are another example of shared &#8220;out-of-band&#8221; information.</li>
<li>However not all contracts are equal in the generality, flexibility and evolvability they allow. Having the contract include a fixed resource URI is very different from having the contract defining a link relation. The former prohibits any change on the URI structure (e.g. host name, HTTP vs HTTPS, embedded information), while the later one enables it. Therefore, designing the contract is a very important task when creating HTTP APIs. And since the transfer contract is already rather well defined by HTTP, most of the design emphasis should be on the representation contract, include the hypermedia components.</li>
<li>Also, not all contracts have the same cost to implement (e.g. having hardcoded URIs is probably simpler than having to find links on representations), so (as usual) trade-offs have to be taken into account.</li>
<li>When implementing HTTP APIs is also very important to have the contract-related areas clearly identified. For me, this typically involves being able to easily answering questions such as: &#8211; Will I be breaking the contract if
<ul>
<li>I change this property name on this model?</li>
<li>I add a new property to this model?</li>
<li>I change the routing rules (e.g. adding a new path segment)?</li>
</ul>
</li>
</ul>
<p>Hope this helps<br />
Looking forward for feedback</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://pfelix.wordpress.com/2016/08/27/on-contracts-and-http-apis/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1545</post-id>
		<media:content url="https://2.gravatar.com/avatar/2f120f7985f2306ba6ef1b49b657ecb30c5c6517257d495d5d9c574b634c2eba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pedrofelix</media:title>
		</media:content>
	</item>
		<item>
		<title>Focus on the representation semantics, leave the transfer semantics to HTTP</title>
		<link>https://pfelix.wordpress.com/2016/08/22/focus-on-the-representation-semantics-leave-the-transfer-semantics-to-http/</link>
					<comments>https://pfelix.wordpress.com/2016/08/22/focus-on-the-representation-semantics-leave-the-transfer-semantics-to-http/#respond</comments>
		
		<dc:creator><![CDATA[pedrofelix]]></dc:creator>
		<pubDate>Mon, 22 Aug 2016 16:22:09 +0000</pubDate>
				<category><![CDATA[Software]]></category>
		<guid isPermaLink="false">http://pfelix.wordpress.com/?p=1533</guid>

					<description><![CDATA[A couple of days ago I was reading the latest OAuth 2.0 Authorization Server Metadata document version and my eye got caught on one sentence. On section 3.2, the document states A successful response MUST use the 200 OK HTTP status code and return a JSON object using the &#8220;application/json&#8221; content type (&#8230;) My first reaction [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>A couple of days ago I was reading the latest <a href="https://tools.ietf.org/html/draft-ietf-oauth-discovery-04">OAuth 2.0 Authorization Server Metadata</a> document version and my eye got caught on one sentence. On <a href="https://tools.ietf.org/html/draft-ietf-oauth-discovery-04#section-3.2">section 3.2</a>, the document states</p>
<blockquote><p>A successful response MUST use the 200 OK HTTP status code and return a JSON object using the &#8220;application/json&#8221; content type (&#8230;)</p></blockquote>
<p>My first reaction was thinking that this specification was being redundant: of course a 200 OK HTTP status should be returned on a successful response. However, that &#8220;MUST&#8221; in the text made me think: is a 200 really the <em>only</em> acceptable response status code for a successful response? In my opinion, the answer is no.</p>
<p>For instance, if caching and ETags are being used, the client can send a conditional GET request (see <a href="https://tools.ietf.org/html/rfc7232">Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests</a>) using the <code>If-None-Match</code> header, for which a 304 (Not Modified) status code is perfectly acceptable. Another example is if the metadata location changes and the server responds with a 301 (Moved Permanently) or a 302 (Found) status code.Does that means the request was unsuccessful? In my opinion, no. It just means that the request should be followed by a subsequent request to another location.</p>
<p>So, why does this little observation deserve a blog post?<br />
Well, mainly because it reflects two common tendencies when designing HTTP APIs (or HTTP interfaces):</p>
<ul>
<li>First, the tendency to redefine transfer semantics that are already defined by HTTP.</li>
<li>Secondly, a very simplistic view of HTTP, ignoring parts such as caching and optimistic concurrency.</li>
</ul>
<p>The HTTP specification already defines a quite rich set of mechanisms for representation transfer, and HTTP related specifications should take advantage of that. What HTTP does not define is the semantics of the representation itself. That should be the focus of specifications such as the <a href="https://tools.ietf.org/html/draft-ietf-oauth-discovery-04">OAuth 2.0 Authorization Server Metadata</a>.</p>
<p>When defining HTTP APIs, focus on the representation semantics. The transfer semantics is already defined by the HTTP protocol.</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://pfelix.wordpress.com/2016/08/22/focus-on-the-representation-semantics-leave-the-transfer-semantics-to-http/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1533</post-id>
		<media:content url="https://2.gravatar.com/avatar/2f120f7985f2306ba6ef1b49b657ecb30c5c6517257d495d5d9c574b634c2eba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pedrofelix</media:title>
		</media:content>
	</item>
		<item>
		<title>Client-side development on OS X using Windows hosted HTTP Web APIs</title>
		<link>https://pfelix.wordpress.com/2016/06/21/client-side-development-on-os-x-using-windows-hosted-http-web-apis/</link>
					<comments>https://pfelix.wordpress.com/2016/06/21/client-side-development-on-os-x-using-windows-hosted-http-web-apis/#respond</comments>
		
		<dc:creator><![CDATA[pedrofelix]]></dc:creator>
		<pubDate>Tue, 21 Jun 2016 16:18:26 +0000</pubDate>
				<category><![CDATA[Software]]></category>
		<guid isPermaLink="false">http://pfelix.wordpress.com/?p=1521</guid>

					<description><![CDATA[In a recent post I described my Android development environment, based on a OS X host, the Genymotion Android emulator, and a Windows VM to run the back-end HTTP APIs. In this post I&#8217;ll describe a similar environment but now for browser-side applications, once again using Windows hosted HTTP APIs. Recently I had to do some [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In a recent <a href="https://pfelix.wordpress.com/2016/03/05/using-fiddler-for-an-android-and-windows-vm-development-environment/" target="_blank">post</a> I described my Android development environment, based on a OS X host, the Genymotion Android emulator, and a Windows VM to run the back-end HTTP APIs.<br />
In this post I&#8217;ll describe a similar environment but now for browser-side applications, once again using Windows hosted HTTP APIs.</p>
<p>Recently I had to do some prototyping involving browser-based applications, using ES6 and React, that interact with IdentityServer3 and a HTTP API.<br />
Both the <a href="https://github.com/IdentityServer/IdentityServer3" target="_blank">IdentityServer3</a> server and the ASP.NET HTTP APIs are running on a Windows VM, however I prefer to use the host OS X environment for the client side development (node, npm, webpack, babel, &#8230;).<br />
Another requirement is that the server side uses HTTPS and multiple name hosts (e.g. <strong>id.example.com</strong>, <strong>app1.example.com</strong>, <strong>app2.example.com</strong>), as described in this previous <a href="https://pfelix.wordpress.com/2016/06/18/using-multiple-iis-server-certificates-on-windows-7/" target="_blank">post</a>.</p>
<p>The solution that I ended up using for this environment is the following:</p>
<ul>
<li>On the Windows VM side I have Fiddler running on port 8888 with &#8220;Allow remote computer to connect&#8221; enabled. This means that Fiddler will act as a proxy even for requests originating from outside the Windows VM.</li>
<li>On the OS X host I launch Chrome with <strong>open -a &#8220;/Applications/Google Chrome.app&#8221; &#8211;args &#8211;proxy-server=10.211.55.3:8888 &#8211;proxy-bypass-list=localhost</strong>, where <strong>10.221.55.3</strong> is the Windows VM address. To automate this procedure I use the automator <a href="http://www.macworld.co.uk/how-to/mac-software/what-automator-can-do-for-you-3605538/" target="_blank">tool</a>  to create a shell script based workflow.</li>
</ul>
<p>The end result, depicted in the following diagram, is that all requests (except for localhost) will be forwarded to the Fiddler instance running on the Windows VM, which will use the Windows hosts file to direct the request to the multiple IIS sites.</p>
<p><img loading="lazy" data-attachment-id="1530" data-permalink="https://pfelix.wordpress.com/2016/06/21/client-side-development-on-os-x-using-windows-hosted-http-web-apis/hosting/" data-orig-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/hosting.png" data-orig-size="1280,720" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="hosting" data-image-description="" data-image-caption="" data-medium-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/hosting.png?w=300" data-large-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/hosting.png?w=625" class="alignnone size-full wp-image-1530" src="https://pfelix.wordpress.com/wp-content/uploads/2016/06/hosting.png" alt="hosting" width="1280" height="720" srcset="https://pfelix.wordpress.com/wp-content/uploads/2016/06/hosting.png 1280w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/hosting.png?w=150&amp;h=84 150w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/hosting.png?w=300&amp;h=169 300w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/hosting.png?w=768&amp;h=432 768w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/hosting.png?w=1024&amp;h=576 1024w" sizes="(max-width: 1280px) 100vw, 1280px" /><br />
As a bonus, I also have full visibility on the HTTP messages.</p>
<p>And that&#8217;s it. I hope it helps.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://pfelix.wordpress.com/2016/06/21/client-side-development-on-os-x-using-windows-hosted-http-web-apis/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1521</post-id>
		<media:content url="https://2.gravatar.com/avatar/2f120f7985f2306ba6ef1b49b657ecb30c5c6517257d495d5d9c574b634c2eba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pedrofelix</media:title>
		</media:content>

		<media:content url="https://pfelix.wordpress.com/wp-content/uploads/2016/06/hosting.png" medium="image">
			<media:title type="html">hosting</media:title>
		</media:content>
	</item>
		<item>
		<title>Using multiple IIS server certificates on Windows 7</title>
		<link>https://pfelix.wordpress.com/2016/06/18/using-multiple-iis-server-certificates-on-windows-7/</link>
					<comments>https://pfelix.wordpress.com/2016/06/18/using-multiple-iis-server-certificates-on-windows-7/#comments</comments>
		
		<dc:creator><![CDATA[pedrofelix]]></dc:creator>
		<pubDate>Sat, 18 Jun 2016 18:03:02 +0000</pubDate>
				<category><![CDATA[Software]]></category>
		<guid isPermaLink="false">http://pfelix.wordpress.com/?p=1486</guid>

					<description><![CDATA[Nowadays I do most of my Windows development on a Windows 7 VM running on OS X macOS (Windows 8 and Windows Server 2012 left some scars so I&#8217;m very reluctance on moving to Windows 10). On this development environment I like to mimic some production environment characteristics, namely: Using IIS based hosting Having each [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Nowadays I do most of my Windows development on a Windows 7 VM running on <del>OS X</del> macOS (Windows 8 and Windows Server 2012 left some scars so I&#8217;m very reluctance on moving to Windows 10). On this development environment I like to mimic some production environment characteristics, namely:</p>
<ul>
<li>Using IIS based hosting</li>
<li>Having each site using different host names</li>
<li>Using HTTPS</li>
</ul>
<p>For the site names I typically use <strong>example.com</strong> subdomains (e.g. <strong>id.example.com</strong>, <strong>app1.example.com</strong>, <strong>app2.example.com</strong>), which are reserved by IANA for documentation purposes (see <a href="https://tools.ietf.org/html/rfc6761" target="_blank">RFC 6761</a>). I associate these names to local addresses via the <a href="https://en.wikipedia.org/wiki/Hosts_(file)" target="_blank"><strong>hosts</strong></a> file.</p>
<p>For generating the server certificates I use <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa386968(v=vs.85).aspx" target="_blank"><strong>makecert</strong></a> and the scripts published at <a href="http://chimera.labs.oreilly.com/books/1234000001708/apg.html#_creating_test_keys_and_certificates">Appendix G</a> of the <a href="http://shop.oreilly.com/product/0636920026617.do" target="_blank">Designing Evolvable Web APIs with ASP.NET</a>.</p>
<p>However, having multiple sites using distinct certificates hosted on the same IP and port address presents some challenges. This is because IIS/HTTP.SYS uses the <strong>Host</strong> header to demultiplex the incoming requests to the different sites bound to the same IP and port.<br />
However, when using TLS, the server certificate must be provided on the TLS handshake, well before the TLS connection is established and the Host header is received. Since at this time HTTP.SYS does not know the target site it also cannot select the appropriate certificate.</p>
<p><strong>Server Name Indication</strong> (SNI) is a TLS extension (see <a href="https://www.ietf.org/rfc/rfc3546.txt">RFC 3546</a>) that addresses this issue, by letting the client send the host name in the TLS handshake, allowing the server to identity the target site and use the corresponding certificate.</p>
<p>Unfortunately, HTTP.SYS on Windows 7 does not support SNI (that&#8217;s what I get for using 2009 operating systems). To circumvent this I took advantage of the fact that there are more loopback addresses other than 127.0.0.1. So, what I do is to use different loopback IP addresses for each site on my machine as illustrated by the following my hosts file excerpt</p>
<pre>127.0.0.2 app1.example.com
127.0.0.3 app2.example.com
127.0.0.4 id.example.com</pre>
<p>When I configure the HTTPS IIS bindings I explicitly configure the listening IP addresses using these different values for each site, which allows me to use different certificates.</p>
<p>And that&#8217;s it. Hope it helps.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://pfelix.wordpress.com/2016/06/18/using-multiple-iis-server-certificates-on-windows-7/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1486</post-id>
		<media:content url="https://2.gravatar.com/avatar/2f120f7985f2306ba6ef1b49b657ecb30c5c6517257d495d5d9c574b634c2eba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pedrofelix</media:title>
		</media:content>
	</item>
		<item>
		<title>The OpenID Connect Cast of Characters</title>
		<link>https://pfelix.wordpress.com/2016/06/06/the-openid-connect-cast-of-characters/</link>
					<comments>https://pfelix.wordpress.com/2016/06/06/the-openid-connect-cast-of-characters/#respond</comments>
		
		<dc:creator><![CDATA[pedrofelix]]></dc:creator>
		<pubDate>Mon, 06 Jun 2016 11:08:49 +0000</pubDate>
				<category><![CDATA[Software]]></category>
		<guid isPermaLink="false">http://pfelix.wordpress.com/?p=1270</guid>

					<description><![CDATA[Introduction The OpenID Connect protocol provides support for both delegated authorization and federated authentication, unifying features that traditionally were provided by distinct protocols. As a consequence, the OpenID Connect protocol parties play multiple roles at the same time, which can sometimes be hard to grasp. This post aims to clarify this, describing how the OpenID [&#8230;]]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p>The <a href="http://openid.net/specs/openid-connect-core-1_0.html" target="_blank">OpenID Connect</a> protocol provides support for both delegated authorization and federated authentication, unifying features that traditionally were provided by distinct protocols. As a consequence, the OpenID Connect protocol parties play multiple roles at the same time, which can sometimes be hard to grasp. This post aims to clarify this, describing how the OpenID Connect parties related to each other and to the equivalent parties in previous protocols, namely OAuth 2.0.</p>
<h2>OAuth 2.0</h2>
<p>The <a href="https://tools.ietf.org/rfc/rfc6750.txt" target="_blank">OAuth 2.0</a> authorization framework introduced a new set of characters into the distributed access control story.</p>
<p><img loading="lazy" data-attachment-id="1479" data-permalink="https://pfelix.wordpress.com/2016/06/06/the-openid-connect-cast-of-characters/oauth2-1/" data-orig-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-1.png" data-orig-size="1139,705" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="oauth2-1" data-image-description="" data-image-caption="" data-medium-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-1.png?w=300" data-large-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-1.png?w=625" class=" size-full wp-image-1479 aligncenter" src="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-1.png" alt="oauth2-1" width="1139" height="705" srcset="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-1.png 1139w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-1.png?w=150&amp;h=93 150w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-1.png?w=300&amp;h=186 300w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-1.png?w=768&amp;h=475 768w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-1.png?w=1024&amp;h=634 1024w" sizes="(max-width: 1139px) 100vw, 1139px" /></p>
<ul>
<li>The<strong> User</strong> (aka <strong>Resource Owner</strong>) is a human with the capability to authorize access to a set of protected resources (e.g. the user is the resources owner).</li>
<li>The <strong>Resource Server</strong> is the HTTP server exposing access to the protected resources via an HTTP API. This access is dependent on the presence and validation of access tokens in the HTTP request.</li>
<li>The <strong>Client Application</strong> is the an HTTP client that accesses user resources on the Resource Server. To perform these accesses, the client application needs to obtain <strong>access tokens</strong> issued by the Authorization Server.</li>
<li>The <strong>Authorization Server</strong> is the party issuing the access tokens used by the Clients Application on the requests to the Resource Server.</li>
<li><strong>Access Tokens</strong> are strings created by the Authorization Server and targeted to the Resource Server. They are opaque to the Client Application, which just obtains them from the Authorization Server and uses them on the Resource Server without any further processing.</li>
</ul>
<p>To make things a little bit more concrete, leet&#8217;s look at an example</p>
<ul>
<li>The <strong>User</strong> is Alice and the protected resources are her repositories at GitHub.</li>
<li>The <strong>Resource Server</strong> is GitHub&#8217;s API.</li>
<li>The <strong>Client Application</strong> is a third-party application, such as Huboard or Travis CI, that needs to access Alice&#8217;s repositories.</li>
<li>The <strong>Authorization Server</strong> is also GitHub, providing the OAuth 2.0 protocol &#8220;endpoints&#8221; for the client application to obtain the access tokens.</li>
</ul>
<p>OAuth 2.0 models the Resource Server and the Authorisation Server as two distinct parties, however they can be run by the same organization (GitHub, in the previous example).</p>
<p><img loading="lazy" data-attachment-id="1481" data-permalink="https://pfelix.wordpress.com/2016/06/06/the-openid-connect-cast-of-characters/oauth2-2-3/" data-orig-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-22.png" data-orig-size="1156,733" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="oauth2-2" data-image-description="" data-image-caption="" data-medium-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-22.png?w=300" data-large-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-22.png?w=625" class=" size-full wp-image-1481 aligncenter" src="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-22.png" alt="oauth2-2" width="1156" height="733" srcset="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-22.png 1156w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-22.png?w=150&amp;h=95 150w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-22.png?w=300&amp;h=190 300w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-22.png?w=768&amp;h=487 768w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-22.png?w=1024&amp;h=649 1024w" sizes="(max-width: 1156px) 100vw, 1156px" /></p>
<p>An important characteristics to emphasise is that the access token <strong>does not</strong> directly provide any information about the User to the Client Application &#8211; it simply provides access to a set of protected resources. The fact that some of these protected resources may be used to provide information about the User&#8217;s identity is out of scope of OAuth 2.0.</p>
<h2>Delegated Authentication and Identity Federation</h2>
<p>However delegated authentication and identity federation protocols, such as the <a href="https://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf" target="_blank">SAML protocols</a> or the <a href="http://docs.oasis-open.org/wsfed/federation/v1.2/ws-federation.html" target="_blank">WS-Federation</a> protocol, use a different terminology.</p>
<p><img loading="lazy" data-attachment-id="1482" data-permalink="https://pfelix.wordpress.com/2016/06/06/the-openid-connect-cast-of-characters/federation-3/" data-orig-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation3.png" data-orig-size="834,700" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="federation" data-image-description="" data-image-caption="" data-medium-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation3.png?w=300" data-large-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation3.png?w=625" class="  wp-image-1482 aligncenter" src="https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation3.png" alt="federation" width="587" height="493" srcset="https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation3.png?w=587&amp;h=493 587w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation3.png?w=150&amp;h=126 150w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation3.png?w=300&amp;h=252 300w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation3.png?w=768&amp;h=645 768w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation3.png 834w" sizes="(max-width: 587px) 100vw, 587px" /></p>
<ul>
<li>The <strong>Relying Party</strong> (or <strong>Service Provider</strong> in the SAML protocol terminology) is typically a Web application that delegates user authentication into an external <strong>Identity Provider</strong>.</li>
<li>The <strong>Identity Provider</strong> is the entity authenticating the user and communicating her identity claims to the <strong>Relying Party</strong>.</li>
<li>The identity claims communication between these two parties is made via identity tokens, which are protected containers for identity claims
<ul>
<li>The Identity Provider creates the identity token.</li>
<li>The Relying Party consumes the identity token by validating it and using the contained identity claims.</li>
</ul>
</li>
</ul>
<p>Sometimes the same entity can play both roles. For instance, an <strong>Identity Provider</strong> can re-delegate the authentication process to another <strong>Identity Provider</strong>. For instance:</p>
<ul>
<li>An Organisational Web application (e.g. order management) delegates the user authentication process to the Organisational Identity Provider.</li>
<li>However, this Organisational Identity Provider re-delegate user authentication into a Partner Identity Provider.</li>
<li>In this case, the Organisational Identity Provider is simultaneously
<ul>
<li>A <strong>Relying Party</strong> for the authentication made by the Partner Identity Provider.</li>
<li>An <strong>Identity Provider</strong>, providing identity claims to the Organisational Web Application.</li>
</ul>
</li>
</ul>
<p><img loading="lazy" data-attachment-id="1483" data-permalink="https://pfelix.wordpress.com/2016/06/06/the-openid-connect-cast-of-characters/federation-2-2/" data-orig-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation-2.png" data-orig-size="1075,1161" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="federation-2" data-image-description="" data-image-caption="" data-medium-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation-2.png?w=278" data-large-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation-2.png?w=625" class="alignnone size-full wp-image-1483" src="https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation-2.png" alt="federation-2" width="1075" height="1161" srcset="https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation-2.png 1075w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation-2.png?w=139&amp;h=150 139w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation-2.png?w=278&amp;h=300 278w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation-2.png?w=768&amp;h=829 768w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation-2.png?w=948&amp;h=1024 948w" sizes="(max-width: 1075px) 100vw, 1075px" /></p>
<p>In these protocols, the main goal of the identity token is to provide identity information about the User to the Relying Party. Namely, the identity token is not aimed to provide access to a set of protected resources. This characteristic sharply contrasts with OAuth 2.0 access tokens.</p>
<h2>OpenID Connect</h2>
<p>The OpenID Connect protocol is <a href="http://openid.net/specs/openid-connect-core-1_0.html#Introduction">&#8220;a simple identity layer on top of the OAuth 2.0 protocol&#8221;</a>, providing both delegated authorisation as well as authentication delegation and identity federation. It unifies in a single protocol the functionalities that previously were provided by distinct protocols. As consequence, now there are multiple parties that play more than one role</p>
<ul>
<li>The <strong>OpenID Provider</strong> (new term introduced by the OpenID Connect specification) is an <strong>Identity Provider</strong> and an <strong>Authorization Server</strong>, simultaneously<strong> </strong>issuing identity tokens and access tokens.</li>
<li>The <strong>Relying Party</strong> is also a <strong>Client Application</strong>. It receives both identity tokens and access tokens from the OpenID Provider. However, there is a significant different in how these tokens are used by this party
<ul>
<li>The identity tokens are consumed by the <strong>Relying Party</strong>/<strong>Client Application</strong> to obtain the user&#8217;s identity.</li>
<li>The access tokens are not directly consumed by the <strong>Relying Party</strong>. Instead they are attached to requests made to the <strong>Resource Server</strong>, without ever being opened at the <strong>Relying Party</strong>.</li>
</ul>
</li>
</ul>
<p><img loading="lazy" data-attachment-id="1484" data-permalink="https://pfelix.wordpress.com/2016/06/06/the-openid-connect-cast-of-characters/oidc-5/" data-orig-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oidc4.png" data-orig-size="1131,699" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="oidc" data-image-description="" data-image-caption="" data-medium-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oidc4.png?w=300" data-large-file="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oidc4.png?w=625" class="alignnone size-full wp-image-1484" src="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oidc4.png" alt="oidc" width="1131" height="699" srcset="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oidc4.png 1131w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/oidc4.png?w=150&amp;h=93 150w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/oidc4.png?w=300&amp;h=185 300w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/oidc4.png?w=768&amp;h=475 768w, https://pfelix.wordpress.com/wp-content/uploads/2016/06/oidc4.png?w=1024&amp;h=633 1024w" sizes="(max-width: 1131px) 100vw, 1131px" /></p>
<p>I hope this post shed some light into the dual nature of the parties in the OpenID Connect protocol.</p>
<p>Please, feel free to use the comments section to place any question.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://pfelix.wordpress.com/2016/06/06/the-openid-connect-cast-of-characters/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1270</post-id>
		<media:content url="https://2.gravatar.com/avatar/2f120f7985f2306ba6ef1b49b657ecb30c5c6517257d495d5d9c574b634c2eba?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pedrofelix</media:title>
		</media:content>

		<media:content url="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-1.png" medium="image">
			<media:title type="html">oauth2-1</media:title>
		</media:content>

		<media:content url="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oauth2-22.png" medium="image">
			<media:title type="html">oauth2-2</media:title>
		</media:content>

		<media:content url="https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation3.png" medium="image">
			<media:title type="html">federation</media:title>
		</media:content>

		<media:content url="https://pfelix.wordpress.com/wp-content/uploads/2016/06/federation-2.png" medium="image">
			<media:title type="html">federation-2</media:title>
		</media:content>

		<media:content url="https://pfelix.wordpress.com/wp-content/uploads/2016/06/oidc4.png" medium="image">
			<media:title type="html">oidc</media:title>
		</media:content>
	</item>
	</channel>
</rss>
