<?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 toc="yes"?>
<?rfc tocompact="yes"?>
<?rfc tocdepth="4"?>
<?rfc tocindent="yes"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>

<rfc category="std" docName="draft-ietf-oauth-token-exchange-02"
     ipr="trust200902">
  <front>
    <title>OAuth 2.0 Token Exchange</title>

    <author fullname="Michael B. Jones" initials="M.B." surname="Jones">
      <organization>Microsoft</organization>
      <address>
        <email>mbj@microsoft.com</email>
        <uri>http://self-issued.info/</uri>
      </address>
    </author>

    <author fullname="Anthony Nadalin" initials="A." surname="Nadalin">
      <organization>Microsoft</organization>
      <address>
        <email>tonynad@microsoft.com</email>
      </address>
    </author>

    <date day="6" month="July" year="2015" />

    <area>Security</area>
    <workgroup>OAuth Working Group</workgroup>

    <keyword>RFC</keyword>
    <keyword>Request for Comments</keyword>
    <keyword>I-D</keyword>
    <keyword>Internet-Draft</keyword>
    <keyword>JSON Web Token</keyword>
    <keyword>JWT</keyword>
    <keyword>Delegation</keyword>
    <keyword>on-behalf-of</keyword>
    <keyword>act-as</keyword>
    
    <abstract>
      <t>
	This specification defines how to request and obtain
	Security Tokens from OAuth Authorization Servers,
	including enabling one party to act on behalf of another or
	enabling one party to delegate authority to another.
      </t>
    </abstract>

  </front>

  <middle>
    <section anchor="Introduction" title="Introduction">
      <t>
	This specification defines how to request and obtain
	Security Tokens from OAuth Authorization Servers <xref target="RFC6749"/>,
	including enabling one party to act on behalf of another or
	enabling one party to delegate authority to another.
	The functionality defined and the terminology used in this specification
	are intentionally parallel to the functionality and terminology
	defined by <xref target="WS-Trust"/>,
	including On-Behalf-Of and Act-As.
      </t>
      <t>
	A Security Token is a set of information that facilitates
	the sharing of identity and security information across security domains.
	Examples of Security Tokens include
	JSON Web Tokens (JWTs) <xref target="JWT"/> and
	SAML Assertions <xref target="OASIS.saml-core-2.0-os"/>.
	Security Tokens are typically signed to achieve integrity
	and sometimes also encrypted to achieve confidentiality.
	Security Tokens are also described as Assertions in
	<xref target="RFC7521"/>.
      </t>
      <t>
        This specification defines a new Security Token Request
	Grant Type used at the Token Endpoint to convey the parameters for
	a Security Token request and Security Token response parameter
	used in responses to these requests.
	The Security Token Request is a
	<xref target="JWT">JSON Web Token (JWT)</xref>
	that is issued by the requesting party
	that contains parameters of the request as Claims.
      </t>
      <t>
	The Security Tokens obtained could be used in a number of contexts,
	the specifics of which are beyond the scope of this specification.
	Examples include using them with the 
      </t>

      <section anchor="rnc" title="Requirements Notation and Conventions">
	<t>
	  The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
	  "SHOULD", "SHOULD 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>
	  This specification uses the terms "Authorization Server"
	  "Token Endpoint", "Token Request", and "Token Response"
	  defined by <xref target="RFC6749">OAuth 2.0</xref>,
	  and the terms "Claim" and "JWT Claims Set" defined by
	  <xref target="JWT">JSON Web Token (JWT)</xref>.
        </t>
      </section>

      <section title="On-Behalf-Of vs. Impersonation Semantics">
	<t>
	  When principal A acts on behalf of principal B, A is given all
	  the rights that B has within some defined rights context.
	  Whereas, with on-behalf-of semantics, principal A still has its own identity
	  separate from B and it is explicitly understood that while B
	  may have delegated its rights to A, any actions taken are
	  being taken by A and not B. In a sense, A is an agent for B.
	</t>
	<t>
	  On-behalf-of semantics are therefore different than
	  impersonation semantics, with which it is sometimes
	  confused. When principal A impersonates principal B, then in
	  so far as any entity receiving Claims is concerned, they are
	  actually dealing with B. It is true that some members of the
	  identity system might have awareness that impersonation is
	  going on but it is not a requirement. For all intents and
	  purposes, when A is acting for B, A is B.
	</t>
      </section>

    </section>

    <section anchor="SecurityTokenRequest" title="Security Token Request">
      <t>
	A Security Token Request is sent to the Token Endpoint as a
	Token Request message using this Grant Type value:
	<list style="hanging">

          <t hangText="urn:ietf:params:oauth:grant-type:security-token-request">
	    <vspace/>
	    Grant Type value indicating that this Token Request is
	    a Security Token Request.
	  </t>
	</list>
      </t>
      <t>
	A Token Request parameter with a related name is used to convey
	the information contained in Security Token Request as a JWT:
	<list style="hanging">

          <t hangText="security_token_request">
	    <vspace/>
	    Token Request parameter whose value is a JWT containing
	    the Security Token Request information.
	  </t>
	</list>
      </t>
      <figure>
	<preamble>
	  An example Security Token Request
	  (with extra line breaks for display purposes only) follows:
	</preamble>
	<artwork><![CDATA[
  POST /token HTTP/1.1
  Host: server.example.com
  Content-Type: application/x-www-form-urlencoded

  grant_type=urn:ietf:params:oauth:grant-type:security-token-request
  &security_token_request=eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJ ...
  [omitted for brevity]
]]></artwork>
      </figure>

      <t>
	The <spanx style="verb">security_token_request</spanx> parameter value
	is a JWT with the following members:

	<list style="hanging">
	  <t hangText="iss">
	    <vspace/>
	    REQUIRED.
	     Issuer of the principal requesting the Security Token.
	  </t>

	  <t hangText="sub">
	    <vspace/>
	    REQUIRED.
	    Identifier of the principal requesting the Security Token at the issuer.
	  </t>

          <t hangText="security_token_type">
	    <vspace/>
	    OPTIONAL.
	    Identifier for the type of the requested Security Token.
	    If not present, the default is that a JWT is being requested.
	    A JWT can also be requested with the identifier
	    <spanx style="verb">urn:ietf:params:oauth:token-type:jwt</spanx>.
	  </t>

	  <t hangText="scopes">
	    <vspace/>
	    OPTIONAL.
	    Array of strings, each of which represents a service context
	    that the requested Security Token is being requested to be used for.
	    The array MUST contain at least one scope value.
	    The definition of these contexts is outside the scope of this specification.
	    (Note:  This request element serves the same purpose as the WS-Trust
	    AppliesTo RST element.)
	  </t>
	</list>
      </t>
      <t>
	The request JWT MUST be signed by the issuer so the identity of
	the requesting party can be validated
	unless the identity of the requesting party is known to
	the Authorization Server by other means;
	in that case, the JWT can use the <spanx style="verb">alg</spanx>
	value <spanx style="verb">none</spanx>.
      </t>

      <figure>
	<preamble>
	  The following is an example of a JWT Claims Set for
	  a Security Token Request:
	</preamble>
	<artwork><![CDATA[
  {
   "iss": "https://server.example.com",
   "sub": "24400320",
   "scopes": ["example"]
  }
]]></artwork>
      </figure>

      <section anchor="ActAs" title="Act-As Security Token Requests">
	<t>
	  This specification defines the ability to request a Security Token
	  for the requesting party to use to act as the specified party.
	  This is accomplished using this Token Request parameter:
	  <list style="hanging">

	    <t hangText="act_as">
	      <vspace/>
	      This OPTIONAL request parameter indicates that the requested Security Token
	      is expected to contain information about the identity represented by
	      the Security Token that is the value of this parameter,
	      enabling the requesting party to use the returned Security Token to
	      act as this identity.
	      Unless the <spanx style="verb">act_as_type</spanx> parameter is also included
	      and specifies a different token type, the <spanx style="verb">act_as</spanx>
	      parameter MUST contain a Security Token that is a JWT.
	    </t>

	    <t hangText="act_as_type">
	      <vspace/>
	      This OPTIONAL request parameter declares the type of the Security Token
	      in the <spanx style="verb">act_as</spanx> parameter.
	      If the Security Token is a JWT, this identifier is
	      <spanx style="verb">urn:ietf:params:oauth:token-type:jwt</spanx>.
	    </t>

	  </list>
	</t>

	<figure>
	  <preamble>
	    The following is an example of a JWT Claims Set for
	    a Security Token Request using an <spanx style="verb">act_as</spanx> Claim:
	  </preamble>
	  <artwork><![CDATA[
  {
   "iss": "https://server.example.com",
   "sub": "24400320",
   "scopes": ["example"],
   "act_as": "eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJ ..."
  }
]]></artwork>
	</figure>

      </section>

      <section anchor="OnBehalfOf" title="On-Behalf-Of Security Token Requests">
	<t>
	  This specification defines the ability to request a Security Token
	  on behalf of another party.
	  This is accomplished using this Token Request parameter:
	  <list style="hanging">

	    <t hangText="on_behalf_of">
	      <vspace/>
	      This OPTIONAL request parameter indicates that the Security Token
	      is being requested on behalf of another party.
	      The identity of the party upon whose behalf the request is being made
	      is represented by
	      the Security Token that is the value of this parameter.
	      Proof of eligibility to act on behalf of that identity
	      MAY be conveyed by including
	      an <spanx style="verb">actor</spanx> Claim
	      identifying the requesting party in the Security Token,
	      per <xref target="Actor"/>,
	      provided the Security Token is a JWT.
	      Unless the <spanx style="verb">on_behalf_of_type</spanx> parameter is also included
	      and specifies a different token type, the <spanx style="verb">on_behalf_of</spanx>
	      parameter MUST contain a Security Token that is a JWT.
	    </t>

	    <t hangText="on_behalf_of_type">
	      <vspace/>
	      This OPTIONAL request parameter declares the type of the Security Token
	      in the <spanx style="verb">on_behalf_of</spanx> parameter.
	      If the Security Token is a JWT, this identifier is
	      <spanx style="verb">urn:ietf:params:oauth:token-type:jwt</spanx>.
	    </t>
	  </list>
	</t>

	<figure>
	  <preamble>
	    The following is an example of a JWT Claims Set for
	    a Security Token Request using an <spanx style="verb">on_behalf_of</spanx> Claim:
	  </preamble>
	  <artwork><![CDATA[
  {
   "iss": "https://server.example.com",
   "sub": "24400320",
   "scopes": ["example"],
   "on_behalf_of": "eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJ ..."
  }
]]></artwork>
	</figure>
      </section>

    </section>

    <section anchor="SecurityTokenResponse" title="Security Token Response">
      <t>
	A Security Token Response is returned from the Token Endpoint as a
	Token Response message containing these members:
	<list style="hanging">

          <t hangText="security_token">
	    <vspace/>
	    Returned Security Token.
	  </t>

          <t hangText="security_token_type">
	    <vspace/>
	    Identifier for the type of the returned Security Token.
	    If the Security Token is a JWT, this identifier is
	    <spanx style="verb">urn:ietf:params:oauth:token-type:jwt</spanx>.
	  </t>
	</list>
      </t>
      <t>
      </t>
      <figure>
	<preamble>
	  An example successful response is as follows:
	</preamble>
	<artwork><![CDATA[
  HTTP/1.1 200 OK
  Content-Type: application/json;charset=UTF-8
  Cache-Control: no-store
  Pragma: no-cache

  {
   "security_token": "eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJ ...",
   "security_token_type": "urn:ietf:params:oauth:token-type:jwt"
  }
]]></artwork>
      </figure>
    </section>

    <section anchor="Actor" title="Conveying Eligibility to Act As Another Party">
      <t>
	It is useful to be able to make a statement that one party is authorized
	to act on behalf of another party.
	This can be done by having the party being acted for issue
	a Security Token containing a Claim identifying the party that will
	act for it as an authorized actor.
	This statement can also optionally identify scopes in which
	the actor is eligible to act through another Claim.
	The following Claims are defined for use in JWTs for these purposes:

	<list style="hanging">
	  <t hangText="actor">
	    <vspace/>
	    Security Token that identifies a party that is asserted as being eligible
	    to act for the party identified by the JWT containing this Claim.
	  </t>

	  <t hangText="scopes">
	    <vspace/>
	    OPTIONAL.
	    Array of strings, each of which represents a service context
	    for which the actor is asserted as being eligible
	    to act for the party identified by the JWT containing this Claim.
	    The array MUST contain at least one scope value.
	    The definition of these contexts is outside the scope of this specification.
	  </t>
	</list>
      </t>
      <t>
	The JWT issued by the party being acted for MUST be signed so the identity of
	the party being acted for can be validated
	unless the identity of the party being acted for is known to
	the Authorization Server by other means;
	in that case, the JWT can use the <spanx style="verb">alg</spanx>
	value <spanx style="verb">none</spanx>.
      </t>
    </section>

    <section anchor="ImplementationConsiderations" title="Implementation Considerations">
      <t>
	Implementations of the specification MUST implement support for using JWTs
	as the Security Tokens.  Other Security Token types MAY be supported.
      </t>
    </section>

    <section anchor="IANA" title="IANA Considerations">
      <t>
        The <spanx style="verb">urn:ietf:params:oauth:grant-type:security-token-request</spanx>
	Grant Type is to be registered in the
	"OAuth URI" registry established by
	<xref target="RFC6755">"An IETF URN Sub-Namespace for OAuth"</xref>.
      </t>
      <t>
        The <spanx style="verb">scopes</spanx>,
	<spanx style="verb">act_as</spanx>,
	<spanx style="verb">act_as_type</spanx>,
	<spanx style="verb">on_behalf_of</spanx>,
	and <spanx style="verb">on_behalf_of_type</spanx>
	Claims are to be registered in the
	IANA "JSON Web Token Claims" registry
	established by <xref target="JWT"/>.
      </t>

    </section>

    <section anchor="Security" title="Security Considerations">
      <t>
        All of the normal security issues, especially in relationship
        to comparing URIs and dealing with unrecognized values, that
        are discussed in <xref target="JWT">JWT</xref> also apply
        here.
      </t>
      <t>
        In addition, on-behalf-of introduces its own unique security
        issues.  Any time one principal is delegated the rights of
        another principal, the potential for abuse is always a concern.
	That is why use of the <spanx style="verb">scopes</spanx>
	member is suggested.
	The scope values restrict the contexts in which
	the delegated rights can be exercised.
      </t>
    </section>
  </middle>

  <back>
    <references title="Normative References">
      <?rfc include='http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml' ?>
      <?rfc include='http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.6749.xml' ?>

      <reference anchor="JWT" target='http://www.rfc-editor.org/info/rfc7519'>
        <front>
          <title>JSON Web Token (JWT)</title>
	  <author fullname="Michael B. Jones" initials="M.B." surname="Jones">
	    <organization>Microsoft</organization>
	    <address>
	      <email>mbj@microsoft.com</email>
	      <uri>http://self-issued.info/</uri>
	    </address>
	  </author>
	  <author fullname="John Bradley" initials="J." surname="Bradley">
	    <organization abbrev="Ping Identity">Ping Identity</organization>
	    <address>
	      <email>ve7jtb@ve7jtb.com</email>
	    </address>
	  </author>
	  <author fullname="Nat Sakimura" initials="N." surname="Sakimura">
	    <organization abbrev="NRI">Nomura Research Institute</organization>
	    <address>
	      <email>n-sakimura@nri.co.jp</email>
	    </address>
	  </author>
	  <date month="May" year="2015"/>
        </front>
        <seriesInfo name="RFC" value="7519"/>
      </reference>

    </references>

    <references title="Informative References">

      <?rfc include='http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.6755.xml' ?>

      <?rfc include='http://xml2rfc.tools.ietf.org/public/rfc/bibxml2/reference.OASIS.saml-core-2.0-os.xml' ?>

      <reference anchor="WS-Trust"
		 target="http://docs.oasis-open.org/ws-sx/ws-trust/v1.4/ws-trust.html">
	<front>
	  <title>WS-Trust 1.4</title>

	  <author fullname="Anthony Nadalin" initials="A." surname="Nadalin">
	  </author>

	  <author fullname="Marc Goodner" initials="M." surname="Goodner">
	  </author>

	  <author fullname="Martin Gudgin" initials="M." surname="Gudgin">
	  </author>

	  <author fullname="Abbie Barbir" initials="A." surname="Barbir">
	  </author>

	  <author fullname="Hans Granqvist" initials="H." surname="Granqvist">
	  </author>

	  <date day="2" month="February" year="2012"/>
	</front>
      </reference>

      <reference anchor="RFC7521" target='http://www.rfc-editor.org/info/rfc7521'>
	<front>
	  <title abbrev="OAuth Assertion Framework">Assertion Framework for OAuth 2.0 Client Authentication and Authorization Grants</title>
	  <author fullname="Brian Campbell" initials="B." surname="Campbell">
	    <organization abbrev="Ping Identity">Ping Identity</organization>
	  </author>
	  <author fullname="Chuck Mortimore" initials="C." surname="Mortimore">
	    <organization abbrev="Salesforce">Salesforce.com</organization>
	  </author>
	  <author fullname="Michael B. Jones" initials="M.B." surname="Jones">
	    <organization abbrev="Microsoft">Microsoft</organization>
	  </author>
	  <author fullname="Yaron Y. Goland" initials="Y.Y." surname="Goland">
	    <organization abbrev="Microsoft">Microsoft</organization>
	  </author>
	  <date month="May" year="2015" />
	</front>
	<seriesInfo name="RFC" value="7521"/>
      </reference>
      
    </references>

   <section title="Open Issues" anchor="TBD">
      <t>
	The following decisions need to be made and updates on this spec performed:
	<list style="symbols">
	  <t>
	    Should we say anything about proof of possession of
	    the target party's key in the On-Behalf-Of case
	    beyond specifying the use of the <spanx style="verb">actor</spanx> Claim?
	  </t>
	  <t>
	    Revise the text in the On-Behalf-Of vs. Impersonation Semantics section
	    to better align the terminology used with the semantics specified.
	  </t>
	  <t>
	    Address the sources of potential terminological confusion discussed
	    in John Bradley's review comments.
	  </t>
	  <t>
	    Add examples illustrating concrete uses of act-as and on-behalf-of.
	  </t>
	</list>
      </t>
    </section>

    <section title='Acknowledgements' anchor='Acknowledgements'>
      <t>
	The authors wish to thank Brian Campbell and John Bradley
	for their reviews of the specification.
      </t>
    </section>

    <section title="Document History" anchor="History">
      <t>
	[[ to be removed by the RFC Editor before publication as an RFC ]]
      </t>

      <t>
        -02
        <list style='symbols'>
	  <t>
	    Enabled use of Security Token types other than JWTs for
	    <spanx style="verb">act_as</spanx> and
	    <spanx style="verb">on_behalf_of</spanx> request values.
	  </t>
          <t>
            Referenced the JWT and OAuth Assertions RFCs.
	  </t>
        </list>
      </t>

      <t>
        -01
        <list style='symbols'>
          <t>
            Updated references.
	  </t>
        </list>
      </t>

      <t>
        -00
        <list style='symbols'>
          <t>
            Created initial working group draft from draft-jones-oauth-token-exchange-01.
	  </t>
        </list>
      </t>
    </section>     

  </back>
</rfc>
