<?xml version="1.0" encoding="utf-8"?>
<!-- name="GENERATOR" content="github.com/mmarkdown/mmark Mmark Markdown Processor - mmark.miek.nl" -->
<rfc version="3" ipr="trust200902" docName="draft-bertocci-oauth-step-up-authn-challenge-01" submissionType="IETF" category="std" xml:lang="en" xmlns:xi="http://www.w3.org/2001/XInclude" consensus="true">

<front>
<title abbrev="OAuth Authn Challenge">OAuth 2.0 Step-up Authentication Challenge Protocol</title><seriesInfo value="draft-bertocci-oauth-step-up-authn-challenge-01" stream="IETF" status="standard" name="Internet-Draft"></seriesInfo>
<author initials="V." surname="Bertocci" fullname="Vittorio Bertocci"><organization>Auth0/Okta</organization><address><postal><street></street>
</postal><email>vittorio@auth0.com</email>
</address></author>
<author initials="B." surname="Campbell" fullname="Brian Campbell"><organization>Ping Identity</organization><address><postal><street></street>
</postal><email>bcampbell@pingidentity.com</email>
</address></author>
<date/>
<area>Security</area>
<workgroup>Web Authorization Protocol</workgroup>
<keyword>security</keyword>
<keyword>oauth2</keyword>
<keyword>openid connect</keyword>
<keyword>oauth</keyword>
<keyword>step-up</keyword>

<abstract>
<t>It is not uncommon for resource servers to require different authentication strengths or freshness according to the characteristics of a request. This document introduces a mechanism for a resource server to signal to a client that the authentication event associated with the access token of the current request doesn't meet its authentication requirements and specify how to meet them.
This document also codifies a mechanism for a client to request that an authorization server achieve a specific authentication strength or freshness when processing an authorization request.</t>
</abstract>

</front>

<middle>

<section anchor="Introduction"><name>Introduction</name>
<t>In simple API authorization scenarios, an authorization server will statically determine what authentication technique to use to handle a given request on the basis of aspects such as the scopes requested, the resource, the identity of the client and other characteristics known at provisioning time.
Although the approach is viable in many situations, it falls short in several important circumstances. Consider, for instance, an eCommerce API requiring different authentication strengths depending on whether the item being purchased exceeds a certain threshold, dynamically estimated by the API itself using a logic that is opaque to the authorization server.
An API might also determine that  a more recent user authentication is required based on its own risk evaluation of the API request.</t>
<t>This document extends the error codes collection defined by <xref target="RFC6750"></xref> with a new value, <tt>insufficient_user_authentication</tt>, which can be used by resource servers to signal to the client that the authentication event associated with the access token presented with the request doesn't meet the authentication requirements of the resource server.
This document also introduces <tt>acr_values</tt> and <tt>max_age</tt> parameters for the <tt>WWW-Authenticate</tt> response header defined by <xref target="RFC6750"></xref>, which the resource server can use to explicitly communicate to the client the required authentication strength or recentness.</t>
<t>The client can use that information to reach back to the authorization server with an authorization request specifying the authentication requirements indicated by protected resource, by including the <tt>acr_values</tt> or <tt>max_age</tt> parameter as defined in <xref target="OIDC"></xref>.</t>
<t>Those extensions will make it possible to implement interoperable step up authentication with minimal work from resource servers, clients and authorization servers.</t>

<section anchor="conventions-and-definitions"><name>Conventions and Definitions</name>
<t>The key words &quot;MUST&quot;, &quot;MUST NOT&quot;, &quot;REQUIRED&quot;, &quot;SHALL&quot;, &quot;SHALL NOT&quot;, &quot;SHOULD&quot;,
&quot;SHOULD NOT&quot;, &quot;RECOMMENDED&quot;, &quot;NOT RECOMMENDED&quot;, &quot;MAY&quot;, and &quot;OPTIONAL&quot; in this
document are to be interpreted as described in BCP 14 <xref target="RFC2119"></xref> <xref target="RFC8174"></xref>
when, and only when, they appear in all capitals, as shown here.</t>
</section>
</section>

<section anchor="protocol-overview"><name>Protocol Overview</name>
<t>Following is an end-to-end sequence of a typical step-up authentication scenario implemented according to this specification.
The scenario assumes that, before the sequence described below takes place, the client already obtained an access token for the protected resource.</t>
<figure anchor="abstract-flow"><name>Abstract protocol flow </name>
<artwork> +----------+                                +--------------+
 |          |                                |              |
 |          |-----(1) resource request------&gt;|              |
 |          |                                |              |
 |          |&lt;-------(2) challenge ----------|   Resource   |
 |          |                                |    Server    |
 |          |                                |              |
 |          |-----(5) resource request -----&gt;|              |
 |          |                                |              |
 |          |&lt;---(6) protected resource -----|              |
 |          |                                +--------------+
 |  Client  | 
 |          |
 |          |                                +---------------+
 |          |                                |               |
 |          |---(3) authorization request---&gt;|               |
 |          |                                |               |
 |          |&lt;-------------...--------------&gt;| Authorization |
 |          |                                |     Server    |
 |          |&lt;------ (4) access token -------|               |
 |          |                                |               |
 +----------+                                +---------------+
</artwork>
</figure>

<ol>
<li>The client requests a protected resource, presenting an access token.</li>
<li>The resource server determines that the circumstances in which the presented access token was obtained offer insufficient authentication strength and/or freshness, hence it denies the request and returns a challenge describing (using a combination of <tt>acr_values</tt> and <tt>max_age</tt>) what authentication requirements must be met for the resource server to authorize a request.</li>
<li>The client directs the user agent to the authorization server with an authorization request that includes the <tt>acr_values</tt> and/or <tt>max_age</tt> indicated by the resource server in the previous step.</li>
<li>After whatever sequence required by the grant of choice plays out, which will include the necessary steps to authenticate the user in accordance with the <tt>acr_values</tt> and/or <tt>max_age</tt> values of the authorization request, the authorization server returns a new access token to the client. The access token contains or references information about the authentication event.</li>
<li>The client repeats the request from step 1, presenting the newly obtained access token.</li>
<li>The resource server finds that the user authentication performed during the acquisition of the new access token complies with its requirements, and returns the requested protected resource.</li>
</ol>
<t>The validation operations mentioned in step 2 and 6 imply that the resource server has a way of evaluating the authentication level by which the access token was obtained. This document will describe how the resource server can perform that determination when the access token is a JWT Access token <xref target="RFC9068"></xref> or is validated via introspection <xref target="RFC7662"></xref>.
Other methods of determining the authentication level by which the access token was obtained are possible, per agreement by the authorization server and the protected resource, but are beyond the scope of this specification.</t>
</section>

<section anchor="authentication-requirements-challenge"><name>Authentication Requirements Challenge</name>
<t>This specification introduces a new error code value for the <tt>error</tt> parameter of <xref target="RFC6750"></xref> or authentication schemes, such as <xref target="I-D.ietf-oauth-dpop"></xref>, which use the <tt>error</tt> parameter:</t>

<dl>
<dt><tt>insufficient_user_authentication</tt></dt>
<dd>The authentication event associated with the access token presented with the request doesn't meet the authentication requirements of the protected resource.</dd>
</dl>
<t>Note: the logic through which the resource server determines that the current request doesn't meet the authentication requirements of the protected resource, and associated functionality (such as expressing, deploying and publishing such requirements) is out of scope for this document.</t>
<t>Furthermore, this specification defines additional <tt>WWW-Authenticate</tt> auth-param values to convey the authentication requirements back to the client.</t>

<dl>
<dt><tt>acr_values</tt></dt>
<dd>A space-separated string indicating, in order of preference, the authentication context class reference values that the protected resource requires the authentication event associated with the access token.</dd>
<dt><tt>max_age</tt></dt>
<dd>Indicates the allowable elapsed time in seconds since the last active authentication event associated with the access token.</dd>
</dl>
<t>Below you can find an example of <tt>WWW-Authenticate</tt> header using the <tt>insufficient_user_authentication</tt> error code value to inform the client that the access token presented isn't sufficient to gain access to the protected resource, and the <tt>acr_values</tt> parameter to let the client know that the expected authentication level corresponds to the authentication context class reference identified by <tt>myACR</tt>.</t>
<figure>
<artwork>HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer error=&quot;insufficient_user_authentication&quot;,
  error_description=&quot;A different authentication level is required&quot;,
  acr_values=&quot;myACR&quot;
</artwork>
</figure>
<t>If the resource server determines that the request is also lacking the scopes required by the requested resource, it MAY include the <tt>scope</tt> attribute with the scope necessary to access the protected resource, as described in section 3.1 of <xref target="RFC6750"></xref>.</t>
</section>

<section anchor="authorization-request"><name>Authorization Request</name>
<t>A client receiving an authorization error from the resource server carrying the error code <tt>insufficient_user_authentication</tt> MAY parse the <tt>WWW-Authenticate</tt> header for  <tt>acr_values</tt> and <tt>max_age</tt> and use them, if present, in a request to the authorization server to obtain a new access token complying with the corresponding requirements.
Both <tt>acr_values</tt> and <tt>max_age</tt> authorization request parameters are OPTIONAL parameters defined in Section 3.1.2.1. of <xref target="OIDC"></xref>. This document does not introduce any changes in the authorization server behavior defined in <xref target="OIDC"></xref> for precessing those parameters, hence any authorization server implementing OpenID Connect will be able to participate in the flow described here with little or no changes. See Section <xref target="AuthzResp"></xref> for more details.</t>
<t>The example request below indicates to the authorization server that the client would like the authentication to occur according to the authentication context class reference identified by <tt>myACR</tt>.</t>
<figure>
<artwork>GET https://as.example.net/authorize?client_id=s6BhdRkqt3
&amp;response_type=code&amp;scope=purchase&amp;acr_values=myACR
</artwork>
</figure>
</section>

<section anchor="AuthzResp"><name>Authorization Response</name>
<t>Section 5.5.1.1 of <xref target="OIDC"></xref> establishes that an authorization server receiving a request containing the <tt>acr_values</tt> parameter MAY attempt to authenticate the user in a manner that satisfies the requested Authentication Context Class Reference, and include the corresponding value in the <tt>acr</tt> claim in the resulting ID Token. The same section also establishes that in case the desired authentication level cannot be met, the authorization server SHOULD include in the <tt>acr</tt> claim a value reflecting the authentication level of the current session (if any). The same section also states that if a request includes thee <tt>max_age</tt> parameter, the authorization server MUST include the <tt>auth_time</tt> claim in the issued ID Token.
An authorization server complying with this specification will react to the presence of the <tt>acr_values</tt> and <tt>max_age</tt> parameters by including <tt>acr</tt> and <tt>auth_time</tt> in the access token (see <xref target="authn-info-in-at"></xref> for details).
Although <xref target="OIDC"></xref> leaves the authorization server free to decide how to handle the inclusion of <tt>acr</tt> in ID Token when requested via <tt>acr_values</tt>, when it comes to access tokens in this specification it is RECOMMENDED that the requested <tt>acr</tt> value is treated as required for successfully fulfilling the request. That is, the requested <tt>acr</tt> value is included in the access token if the authentication operation successfully met its requirements, or that the authorization request fails in all other cases, returning <tt>unmet_authentication_requirements</tt> as defined in <xref target="OIDCUAR"></xref>. The recommended behavior will help prevent clients getting stuck in a loop where the authorization server keeps returning tokens that the resource server already identified as not meeting its requirements hence known to be rejected as well.</t>
</section>

<section anchor="authn-info-in-at"><name>Authentication Information Conveyed via Access Token</name>
<t>To evaluate whether an access token meets the protected resource's requirements, the resource servers needs a way of accessing information about the authentication event by which that access token was obtained. This specification provides guidance on how to convey that information in conjunction with two common access token validation methods: the one described in <xref target="RFC9068"></xref>, where the access token is encoded in JWT format and verified via a set of validation rules, and the one described in <xref target="RFC7662"></xref>, where the token is validated and decoded by sending it to an introspection endpoint.
Authorization servers and resource servers MAY elect to use other encoding and validation methods, however those are out of scope for this document.</t>

<section anchor="jwt-access-tokens"><name>JWT Access Tokens</name>
<t>When access tokens are represented as JSON Web Tokens (JWT) <xref target="RFC7519"></xref>, the <tt>auth_time</tt> and <tt>acr</tt> claims (per Section 2.2.1 of <xref target="RFC9068"></xref>) are used to convey the time and context of the user authentication event that the authentication server performed during the course of obtaining the access token. It is useful to bear in mind that the values of those two parameters are established at user authentication time and won't change in the event of access token renewals. See the aforementioned Section 2.2.1 of <xref target="RFC9068"></xref> for details. The following is a conceptual example showing the decoded content of such a JWT access token.</t>
<figure>
<artwork>Header:

{&quot;typ&quot;:&quot;at+JWT&quot;,&quot;alg&quot;:&quot;RS256&quot;,&quot;kid&quot;:&quot;LTacESbw&quot;}
 
Claims: 

{
 &quot;iss&quot;: &quot;https://as.example.net&quot;,
 &quot;sub&quot;: &quot;someone@example.net&quot;,
 &quot;aud&quot;: &quot;https://rs.example.com&quot;,
 &quot;exp&quot;: 1646343000,
 &quot;iat&quot;: 1646340200,
 &quot;jti&quot; : &quot;e1j3V_bKic8-LAEB_lccD0G&quot;,
 &quot;client_id&quot;: &quot;s6BhdRkqt3&quot;,
 &quot;scope&quot;: &quot;purchase&quot;,
 &quot;auth_time&quot;: 1646340198,
 &quot;acr&quot;: &quot;myACR&quot;
}
</artwork>
</figure>
</section>

<section anchor="intro"><name>OAuth 2.0 Token Introspection</name>
<t>OAuth 2.0 Token Introspection <xref target="RFC7662"></xref> defines a method for a protected resource to query an authorization server about the active state of an access token as well as to determine metainformation about the token.
The following two top-level introspection response members are defined to convey information about the user authentication event that the authentication server performed during the course of obtaining the access token.</t>

<dl>
<dt><tt>acr</tt></dt>
<dd>Authentication Context Class Reference. String specifying an Authentication Context Class Reference value that identifies the Authentication Context Class that the user authentication performed satisfied.</dd>
<dt><tt>auth_time</tt></dt>
<dd>Time when the user authentication occurred. A JSON numeric value representing the number of seconds from 1970-01-01T00:00:00Z UTC until the time of date/time of the authentication event.</dd>
</dl>
<t>The following example shows an introspection response with information about the user authentication event by which the access token was obtained.</t>
<figure>
<artwork>HTTP/1.1 200 OK
Content-Type: application/json

{
  &quot;active&quot;: true,
  &quot;client_id&quot;: &quot;s6BhdRkqt3&quot;,
  &quot;scope&quot;: &quot;purchase&quot;,
  &quot;sub&quot;: &quot;someone@example.net&quot;,
  &quot;aud&quot;: &quot;https://rs.example.com&quot;,
  &quot;iss&quot;: &quot;https://as.example.net&quot;,
  &quot;exp&quot;: 1639528912,
  &quot;iat&quot;: 1618354090,
  &quot;auth_time&quot;: 1646340198,
  &quot;acr&quot;: &quot;myACR&quot;
}
</artwork>
</figure>
</section>
</section>

<section anchor="Security"><name>Security Considerations</name>
<t>[[TBD]]</t>
<t>Remember that oauth is not authN, you need a layer like OIDC to handle that part. This is not an encouragement to abuse oauth. This is about the authentication event of the user to the AS by which the access token was obtained.</t>
</section>

<section anchor="IANA"><name>IANA Considerations</name>
<t>[[TBD]]</t>
<t>The <tt>insufficient_user_authentication</tt> error code in the &quot;OAuth Extensions Error&quot; registry <xref target="IANA.OAuth.Params"></xref>.</t>
<t><xref target="intro"></xref> for <tt>acr</tt> and <tt>auth_time</tt> as top-level members of the introspection response in the &quot;OAuth Token Introspection Response&quot; registry <xref target="IANA.OAuth.Params"></xref>.</t>
<t>The <tt>acr_values</tt> and <tt>max_age</tt> <tt>WWW-Authenticate</tt> auth-params are &quot;new&quot; but doesn't seem like any registration is needed or possible.</t>
</section>

</middle>

<back>
<references><name>Normative References</name>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6750.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7662.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.9068.xml"/>
</references>
<references><name>Informative References</name>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml-ids/reference.I-D.abr-twitter-reply.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml-ids/reference.I-D.ietf-oauth-dpop.xml"/>
<reference anchor="IANA.OAuth.Params" target="https://www.iana.org/assignments/oauth-parameters">
  <front>
    <title>OAuth Parameters</title>
    <author>
      <organization>IANA</organization>
    </author>
    <date></date>
  </front>
</reference>
<reference anchor="OIDC" target="http://openid.net/specs/openid-connect-core-1_0.html">
  <front>
    <title>OpenID Connect Core 1.0 incorporating errata set 1</title>
    <author fullname="Nat Sakimura" initials="N." surname="Sakimura">
      <organization>NRI</organization>
    </author>
    <author fullname="John Bradley" initials="J." surname="Bradley">
      <organization>Ping Identity</organization>
    </author>
    <author fullname="Mike Jones" initials="M." surname="Jones">
      <organization>Microsoft</organization>
    </author>
    <author fullname="Breno de Medeiros" initials="B." surname="de Medeiros">
      <organization>Google</organization>
    </author>
    <author fullname="Chuck Mortimore" initials="C." surname="Mortimore">
      <organization>Salesforce</organization>
    </author>
    <date year="2014" month="Nov" day="8"></date>
  </front>
</reference>
<reference anchor="OIDCUAR" target="https://openid.net/specs/openid-connect-unmet-authentication-requirements-1_0.html">
  <front>
    <title>OpenID Connect Core Error Code unmet_authentication_requirements</title>
    <author fullname="Torsten Lodderstedt" initials="T." surname="Lodderstedt">
      <organization>YES</organization>
    </author>
    <date year="2019" month="May" day="8"></date>
  </front>
</reference>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7519.xml"/>
</references>

<section anchor="Acknowledgements"><name>Acknowledgements</name>
<t>I wanted to thank the Academy, the viewers at home, the shampoo manufacturers, etc..</t>
<t>Initially (kinda) discussed at the OAuth Security Workshop 2021</t>
<t>A number of others already but haven't kept track...</t>
</section>

<section anchor="document-history"><name>Document History</name>
<t>[[ To be removed from the final specification ]]</t>
<t>-01</t>

<ul>
<li>Fixed example</li>
<li>Clarified/noted that scope can also be in the WWW-Authenticate/401</li>
</ul>
<t>-00</t>

<ul>
<li>Initial Individual Draft (with all the authority thereby bestowed <xref target="I-D.abr-twitter-reply"></xref>).</li>
</ul>
</section>

</back>

</rfc>
