<?xml version="1.0" encoding="US-ASCII"?>
<?xml-stylesheet type='text/xsl' href='http://xml2rfc.tools.ietf.org/authoring/rfc2629.xslt' ?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">

<rfc category="std" docName="draft-campbell-oauth-tbpkce-00" ipr="trust200902">

  <?rfc toc="yes" ?>
  <?rfc tocdepth="5" ?>
  <?rfc symrefs="yes" ?>
  <?rfc sortrefs="yes"?>
  <?rfc strict="yes" ?>
  <?rfc compact="yes" ?>
  <?rfc subcompact="no" ?>

  <front>
    <title abbrev="Token Binding PKCE">A Token Binding method for OAuth 2.0 Proof Key for Code Exchange</title>

    <author fullname="Brian Campbell" initials="B." surname="Campbell">
      <organization>Ping Identity</organization>
      <address>
        <email>brian.d.campbell@gmail.com</email>
        <uri>https://twitter.com/__b_c</uri>
      </address>
    </author>

    <author fullname="John Bradley" initials="J." surname="Bradley">
      <organization abbrev="Ping Identity">Ping Identity</organization>
      <address>
        <email>ve7jtb@ve7jtb.com</email>
        <uri>http://www.thread-safe.com/</uri>
      </address>
    </author>

    <author fullname="Michael B. Jones" initials="M.B." surname="Jones">
      <organization abbrev="Microsoft">Microsoft</organization>
      <address>
        <email>mbj@microsoft.com</email>
        <uri>http://self-issued.info/</uri>
      </address>
    </author>

    <date />

    <area>Security</area>
    <workgroup>OAuth Working Group</workgroup>
    <keyword>PKCE</keyword>
    <keyword>OAuth</keyword>
    <keyword>Token Binding</keyword>


    <abstract>
      <t>
        This specification describes a
        <xref target="RFC7636">Proof Key for Code Exchange (PKCE)</xref> method utilizing
        <xref target="I-D.ietf-tokbind-https">Token Binding over HTTP</xref>
        to cryptographically bind the <xref target="RFC6749">OAuth 2.0</xref> authorization
        code to a key pair on the client, which it proves possession of during the access token request with the
        authorization code.
      </t>
    </abstract>
  </front>

  <middle>
    <section anchor="intro" title="Introduction">
      <t>
        This specification minimally describes an <xref target="RFC6749">OAuth 2.0</xref>
        <xref target="RFC7636">PKCE</xref> method based on the
        <xref target="I-D.ietf-tokbind-protocol">Token Binding Protocol</xref> and
        <xref target="I-D.ietf-tokbind-https">Token Binding over HTTP</xref>.
        The general details and motivations of PKCE are discussed in that document and
        this specification defines only the additional pieces needed for a Token Binding
        PKCE method.
      </t>

      <section anchor="rec" title="Requirements Notation and Conventions">
        <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
          "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this
          document are to be interpreted as described in <xref
              target="RFC2119">RFC 2119</xref>.</t>
      </section>

      <section anchor="Terminology" title="Terminology">
        <t> <!-- TODO this -->
          This specification uses the terms "authorization code",
          "authorization endpoint", "authorization server", "authorization request", "access token request",
          "client", and "token endpoint"
          defined by <xref target="RFC6749">OAuth 2.0</xref>,
          and
          the terms "Provided", "Token Binding" and "Token Binding ID"
          defined by <xref target="I-D.ietf-tokbind-https">Token Binding over HTTP</xref>.
        </t>
      </section>
    </section>

    <section anchor="cc" title="Code Challenge">
      <t>
        As defined in <xref target="RFC7636">Proof Key for Code Exchange</xref>,
        the client sends the code challenge as part of the OAuth 2.0
        Authorization Request with the two additional parameters:
        <spanx style="verb">code_challenge</spanx> and <spanx style="verb">code_challenge_method</spanx>.
      </t>
      <t>
        For the Token Binding method of PKCE defined herein, <spanx style='verb'>tb2</spanx>
        is used for the value of the <spanx style="verb">code_challenge_method</spanx> parameter.
      </t>
      <t>
        The value of the <spanx style="verb">code_challenge</spanx> parameter is the base64url encoding
        (per Section 5 of <xref target="RFC4648"/> with all trailing pad ('=')
        characters omitted and without the inclusion of any line breaks or whitespace)
        of the <xref target="RFC6234">SHA-256 hash</xref> of the Provided Token Binding ID
        that the client will use when calling the authorization server's
        token endpoint. Note that, prior to making the authorization request, the client may need to
        establish a TLS connection between itself and the authorization server's token endpoint in order to obtain
        the appropriate Token Binding ID.
      </t>
      <t>
        When the authorization server issues the authorization code in the authorization
        response, it associates the code challenge and method values
        with the authorization code so it can be verified later when the code is
        presented in the access token request.
      </t>
    </section>


    <section anchor="cv" title="Code Verifier">
      <t>
        Upon receipt of the authorization code, the client sends the access
        token request to the token endpoint. The <xref target="I-D.ietf-tokbind-protocol">Token Binding Protocol</xref>
        is negotiated on the TLS connection between the client and the authorization server and the
        <spanx style="verb">Sec-Token-Binding</spanx> header, as defined in
        <xref target="I-D.ietf-tokbind-https">Token Binding over HTTP</xref>,
        is included in the access token request. The authorization server extracts the
        Provided Token Binding ID from the header value, hashes it with SHA-256, and compares
        it to the <spanx style="verb">code_challenge</spanx> value previously associated with the authorization code.
        If the values match, the token endpoint MUST continue processing
        as normal (as defined by <xref target="RFC6749">OAuth 2.0</xref>).  If the values do not
        match, an error response indicating "invalid_grant" MUST be returned.
      </t>
      <t>
        The <spanx style="verb">Sec-Token-Binding</spanx> header contains sufficient information for verification of the
        authorization code and its association to the original authorization request. However, <xref target="RFC7636">PKCE</xref>
        requires that a <spanx style="verb">code_verifier</spanx> parameter be
        sent with the access token request, so the static value <spanx style="verb">provided</spanx> is used to meet that
        requirement and indicate that the Provided Token Binding ID is used for the verification.
      </t>
    </section>

    <section anchor="sec" title="Security Considerations">
      <t>
        TBD
      </t>
    </section>

    <section anchor="IANA" title="IANA Considerations">
      <section anchor="MethodRegistration" title="PKCE Code Challenge Method Registration">

        <t>
          This specification requests registration of the following
          Code Challenge Method Parameter Name
          in the IANA "PKCE Code Challenge Methods" registry
          <xref target="IANA.OAuth.Parameters"/>
          established by <xref target="RFC7636"/>.
        </t>

        <section anchor="TokenTypeContents" title='Registry Contents'>

          <t>
            <?rfc subcompact="yes"?>
            <list style='symbols'>
              <t>Code Challenge Method Parameter Name: tb2</t>
              <t>Change controller: IESG</t>
              <t>Specification document(s): <xref target="cc"/> of [[ this specification ]]</t>
            </list>
          </t>
          <?rfc subcompact="no"?>

        </section>
      </section>
    </section>
  </middle>

  <back>
    <references title="Normative References">

      <?rfc include="http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2119"?>
      <?rfc include="http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.4648"?>  <!-- base64 -->

      <?rfc include="http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.6234"?>

      <?rfc include="http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.6749"?> <!-- OAuth 2.0 -->
      <?rfc include="http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.7636"?> <!-- PKCE -->

      <?rfc include='http://xml2rfc.tools.ietf.org/public/rfc/bibxml3/reference.I-D.draft-ietf-tokbind-protocol-06.xml' ?>
      <?rfc include='http://xml2rfc.tools.ietf.org/public/rfc/bibxml3/reference.I-D.draft-ietf-tokbind-https-03.xml' ?>

      <reference anchor="IANA.OAuth.Parameters" target="http://www.iana.org/assignments/oauth-parameters">
        <front>
          <title>OAuth Parameters</title>
          <author>
            <organization>IANA</organization>
          </author>
          <date/>
        </front>
      </reference>

    </references>

    <section anchor="Acknowledgements" title="Acknowledgements">
      <t>
        Dirk Balfanz,
        William Dennis
        (and others?)
        also provided input to this specification.
      </t>
    </section>

    <section anchor="History" title="Document History">
      <t>[[ to be removed by the RFC Editor before publication as an RFC ]]</t>

      <t>
        draft-campbell-oauth-tbpkce-00
        <list style="symbols">
          <t>
           Initial version.
          </t>
        </list>
      </t>

    </section>

  </back>
</rfc>
