<?xml version="1.0" encoding="US-ASCII"?>


<!DOCTYPE rfc SYSTEM 'rfc2629.dtd'>
<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>

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

<rfc number="7628" submissionType="IETF" consensus="yes" ipr="trust200902" category="std">

  <front>
    <title abbrev="SASL OAuth">A Set of Simple Authentication and Security
    Layer (SASL) Mechanisms for&nbsp;OAuth</title>
    <author fullname="William Mills" initials="W." surname="Mills">
      <organization>Microsoft</organization>
      <address>
        <postal>
          <street/>
          <city/>
          <code/>
          <region/>
          <country/>
        </postal>
        <phone/>
        <email>wmills_92105@yahoo.com</email>
      </address>
    </author>
    <author fullname="Tim Showalter" initials="T." surname="Showalter">
      <organization></organization>
      <address>
        <postal>
          <street/>
          <city/>
          <code/>
          <region/>
          <country/>
          </postal>
        <phone/>
        <email>tjs@psaux.com</email>
      </address>
    </author>

    <author initials="H.T." surname="Tschofenig" fullname="Hannes Tschofenig ">
      <organization>ARM Ltd.</organization>
      <address>
        <postal>
          <street>110 Fulbourn Rd</street>
          <city>Cambridge</city>
          <code> CB1 9NJ </code>
          <country>United Kingdom</country>
        </postal>
        <email>Hannes.tschofenig@gmx.net </email>
        <uri>http://www.tschofenig.priv.at</uri>
      </address>
    </author>

    <date year="2015" month="August" />

<!--note: authors did not have any further keywords to add-->

     <abstract>
       <t>
	 OAuth enables a third-party
    application to obtain limited access to a protected resource, either on
    behalf of a resource owner by orchestrating an approval interaction or by allowing the
    third-party application to obtain access on its own behalf.
    </t>
       <t>This document defines how an application client uses credentials obtained via OAuth
	 over the Simple Authentication and Security Layer (SASL)
	 to access a protected resource at a resource server.  Thereby, it enables
	 schemes defined within the OAuth framework for non-HTTP-based application protocols.
       </t> 
       <t>Clients typically store the user's long-term credential. This does, however, lead to 
       significant security vulnerabilities, for example, when such a
       credential leaks. A significant benefit of OAuth for usage in
       those clients is that the password is replaced by a
       shared secret with higher entropy, i.e., the token. Tokens typically provide limited access rights and can
       be managed and revoked separately from the user's long-term password.
	 </t>
     </abstract>
   </front>

   <middle>

     <section title="Introduction">

	 <t>OAuth 1.0a <xref target="RFC5849"/> and OAuth 2.0 <xref target="RFC6749"/> are protocol frameworks that enable a third-party
	 application to obtain limited access to a protected resource, either 
	 by orchestrating an approval interaction on
	 behalf of a resource owner or by allowing the
	 third-party application to obtain access on its own behalf. </t>

	 <t>The core OAuth 2.0
	 specification <xref target="RFC6749"/> specifies the interaction between the OAuth client and the authorization server; it does not define the interaction between the 
	 OAuth client and the resource server for the access to a protected resource using an access token. 
	 Instead, the OAuth client to resource server interaction is described in separate specifications, such as the bearer token specification <xref
	   target="RFC6750"/>. OAuth 1.0a includes the protocol specification for the communication between the OAuth client and the resource server 
		 in <xref target="RFC5849"/>. 
     </t> 

       <t>The main use cases for OAuth 1.0a and OAuth 2.0 have so far focused on an HTTP-based <xref target="RFC7230"/> environment only. 
 This document integrates OAuth 1.0a and OAuth 2.0 into non-HTTP-based applications using the integration into the Simple Authentication and Security Layer (SASL) <xref target="RFC4422"/>.
 Hence, this document  takes
	 advantage of the OAuth protocol and its deployment base to provide a way to use SASL to gain 
	 access to resources when using non-HTTP-based protocols, such as the Internet Message 
	 Access Protocol (IMAP) <xref target="RFC3501"/> and the Simple Mail Transfer Protocol (SMTP) 
	 <xref target="RFC5321"/>. This document gives examples of use in IMAP and SMTP.</t>

 <t>To illustrate the impact of integrating this specification into an OAuth-enabled application environment, <xref target="overview"/> shows the abstract message flow of OAuth 2.0 <xref target="RFC6749"/>. As indicated in the figure, this document impacts the exchange of messages (E) and (F) since SASL is used for interaction between the client and the resource server instead of HTTP.</t>

	 <figure anchor="overview" title="OAuth 2.0 Protocol Flow">
	   <artwork><![CDATA[
                                                           ----+
+--------+                                  +---------------+  |
|        |--(A)-- Authorization Request --->|   Resource    |  |
|        |                                  |    Owner      |  |Plain
|        |<-(B)------ Access Grant ---------|               |  |OAuth
|        |                                  +---------------+  |2.0
|        |                                                     | 
|        |         Client Credentials &     +---------------+  |
|        |--(C)------ Access Grant -------->| Authorization |  |
| Client |                                  |    Server     |  |
|        |<-(D)------ Access Token ---------|               |  |
|        |      (w/ Optional Refresh Token) +---------------+  |
|        |                                                 ----+
|        |                                                 ----+
|        |                                  +---------------+  |
|        |                                  |               |  |OAuth
|        |--(E)------ Access Token -------->|   Resource    |  |over
|        |                                  |    Server     |  |SASL
|        |<-(F)---- Protected Resource -----|               |  |
|        |                                  |               |  |
+--------+                                  +---------------+  |
                                                           ----+
 ]]></artwork>
	 </figure>

 <t>SASL is a framework
    for providing authentication and data security services in
    connection-oriented protocols via replaceable authentication mechanisms.  It
    provides a structured interface between protocols and mechanisms.
    The resulting framework allows new protocols to reuse existing
    authentication mechanisms and allows old protocols to make use of new authentication mechanisms.
    The framework also provides a protocol for securing subsequent
    exchanges within a data security layer.</t>

 <t>When OAuth is integrated into SASL, the high-level steps are as follows:
 <list style="format (%C)"> 
 <t>     The client requests authorization from the resource owner.  The
	 authorization request can be made directly to the resource owner
	 (as shown) or indirectly via the authorization
	 server as an intermediary.</t>

 <t>     The client receives an authorization grant, which is a credential
	 representing the resource owner's authorization, expressed using
	 one of the grant types defined in <xref target="RFC6749"/> or <xref target="RFC5849"/> or using
	 an extension grant type.  The authorization grant type depends
	 on the method used by the client to request authorization and
	 the types supported by the authorization server.</t>

 <t>   The client requests an access token by authenticating with the
	 authorization server and presenting the authorization grant.</t>

 <t>   The authorization server authenticates the client and validates
	 the authorization grant, and if valid, it issues an access token.</t>

 <t>   The client requests the protected resource from the resource
	 server and authenticates it by presenting the access token.</t>

 <t>   The resource server validates the access token, and if valid,
	 it indicates a successful authentication.</t>
 </list> 
 </t>

 <t>
 Again, steps (E) and (F) are not defined in <xref target="RFC6749"/> (but are
 described in, for example, <xref target="RFC6750"/> for the OAuth bearer token
 instead) and are the main functionality specified within this
 document. Consequently, the message exchange shown in <xref target="overview"/> is the
 result of this specification. The client will generally need to
 determine the authentication endpoints (and perhaps the service
 endpoints) before the OAuth 2.0 protocol exchange messages in steps
 (A)-(D) are executed. The discovery of the resource owner, 
 authorization server endpoints, and client registration are outside 
 the scope of this specification. The client must discover the 
 authorization endpoints using a discovery mechanism such as OpenID
 Connect Discovery (OIDCD) <xref target="OpenID.Discovery" /> or WebFinger using host-meta
 <xref target="RFC7033"/>.  Once credentials are obtained, the client proceeds to steps
 (E) and (F) defined in this specification.  Authorization endpoints
 MAY require client registration, and generic clients SHOULD support
 the Dynamic Client Registration protocol <xref target="RFC7591"/>.
       </t>

	   <t>OAuth 1.0a follows a similar model but uses a different terminology and 
	   does not separate the resource server from the authorization server.</t>

     </section>


     <section title="Terminology">
       <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"/>.</t>
      <t>The reader is assumed to be familiar with the terms used in the OAuth 2.0 specification <xref
          target="RFC6749"/> and SASL <xref target="RFC4422"/>.</t>
      <t>In examples, "C:" and "S:" indicate lines sent by the client and server, respectively. Line
        breaks have been inserted for readability.</t>
      <t>Note that the IMAP SASL specification requires base64 encoding, as specified in Section 4 
         of <xref target="RFC4648"/>.</t>
    </section>


    <section title="OAuth SASL Mechanism Specifications">

      <t>SASL is used as an authentication framework in a variety of application-layer protocols. This
        document defines the following SASL mechanisms for usage with OAuth:
       	<list><t>
	<list style="hanging">	 
         <t hangText="OAUTHBEARER:">OAuth 2.0 bearer tokens, as described in <xref target="RFC6750"/>. RFC 6750 uses 
		Transport Layer Security (TLS) <xref target="RFC5246"/> to secure the protocol interaction between 
	        the client and the resource server.</t>
	  <t hangText="OAUTH10A:">OAuth 1.0a Message Authentication Code (MAC) tokens (using the HMAC-SHA1 keyed message digest), as described in Section 
		3.4.2 of <xref target="RFC5849"/>.
	     </t>
	</list></t></list>
   
    New extensions may be defined to add additional OAuth Access Token Types. Such a new SASL OAuth 
	mechanism can be added by registering the new name(s) with IANA in the SASL Mechanisms registry and citing this
	specification for the further definition.  
     </t>

     <t>
       SASL mechanisms using this document as their definition do not provide
       a data security layer; that is, they cannot provide integrity or
       confidentiality protection for application messages after the initial
       authentication.  If such protection is needed, TLS or some similar
       solution should be used.  Additionally, for the two mechanisms specified
       in this document, TLS MUST be used for OAUTHBEARER to protect the bearer
       token; for OAUTH10A, the use of TLS is RECOMMENDED.
     </t>

     <t>These mechanisms are client initiated and in lockstep, with the server always replying to a client 
	message.  In the case where the client has and correctly uses a valid token, the flow is:

	<list style="numbers">
	  <t>Client sends a valid and correct initial client response.
	     </t>
	  <t>Server responds with a successful authentication.
	   	  </t>
	</list>

	In the case where authentication fails, the server sends an error result; the client MUST
	then send an additional message to the server in order to allow the server to finish the
	exchange.  Some protocols and common SASL implementations do not support both sending a SASL
	message and finalizing a SASL negotiation. The additional client message in the error case
	deals with this problem.  This exchange is:

	<list style="numbers">
		<t>Client sends an invalid initial client response.</t>
		<t>Server responds with an error message. </t>
		<t>Client sends a dummy client response.</t>
		<t>Server fails the authentication.</t>
	</list>
	</t>

      <section title="Initial Client Response">
        <t>Client responses are a GS2 <xref target="RFC5801"/> header followed by zero or more key/value pairs, or it may be empty. The 
	gs2-header rule is defined here as a placeholder for compatibility with GS2 if a GS2 mechanism is formally defined, but this
        document does not define one.  The key/value pairs take the place of the corresponding HTTP headers and
        values to convey the information necessary to complete an OAuth-style HTTP authorization.  
	Unknown key/value pairs MUST be ignored by the server. The ABNF <xref target="RFC5234"/> syntax is:
	</t>

        <figure>
          <artwork type="abnf">
            <![CDATA[
  kvsep          = %x01
  key            = 1*(ALPHA)
  value          = *(VCHAR / SP / HTAB / CR / LF )
  kvpair         = key "=" value kvsep
;;gs2-header     = See RFC 5801
  client-resp    = (gs2-header kvsep *kvpair kvsep) / kvsep]]></artwork>
        </figure>

	<t>The GS2 header MAY include the username associated with the resource being accessed, the "authzid".  
           It is worth noting that application protocols are allowed to require an authzid, as are specific server implementations. 
	</t>
	<t>The client response consisting of only a single kvsep is used only when authentication fails 
	and is only valid in that context.  If sent as the first message from the client, the server MAY
	simply fail the authentication without returning discovery information since there is no user or
	server name indication.
	</t>
	<t>The following keys and corresponding values are defined in the client response: 
	</t>
	<t><list><t>
	  <list style="hanging">
            <t hangText="auth (REQUIRED):">The payload that would be in the HTTP Authorization header
	                                   if this OAuth exchange was being carried out over HTTP.</t>

            <t hangText="host:">Contains the hostname to which the client connected. In 
                                an HTTP context, this is the value of the HTTP Host header. </t>

            <t hangText="port:">Contains the destination port that the client connected to, represented as a
				decimal positive integer string without leading zeros.</t>
          </list>
        </t></list>
	</t>
	<t>
	For OAuth token types such as OAuth 1.0a that use keyed message digests, the client MUST send host and
	port number key/values, and the server MUST fail an authorization request requiring
	keyed message digests that are not accompanied by host and port values.  In 
	OAuth 1.0a, for example, the so-called "signature base string calculation" includes the reconstructed HTTP
	URL.  
	</t>

	<section title="Reserved Key/Values">
	  <t> In these mechanisms, values for path, query string and post body are 
	  assigned default values.  OAuth authorization schemes MAY define usage of
	  these in the SASL context and extend this specification.  For OAuth Access Token Types that 
	  include a keyed message digest of the request, the default values MUST be used unless
	  explicit values are provided in the client response.  The following key
	  values are reserved for future use: 

	    <list><t>
		<list style="hanging">
		  <t hangText="mthd (RESERVED):">HTTP method; the default value is "POST".
		  </t>
		  <t hangText="path (RESERVED):">HTTP path data; the default value is "/".
		  </t>
		  <t hangText="post (RESERVED):">HTTP post data; the default value is the empty string ("").
		  </t>
  	          <t hangText="qs (RESERVED):">The HTTP query string; the default value is the empty string ("").  
  		  </t>
		</list>
	    </t></list>
	  </t>
	</section>


      </section>

      <section title="Server's Response">
      
      <t>The server validates the response according to the specification for the
   	OAuth Access Token Types used.  If the OAuth Access Token Type utilizes a keyed message 
	digest of the request parameters, then the client must provide a client
   	response that satisfies the data requirements for the scheme in use. 
	</t>

	<t>
	  The server fully validates the client response before generating a server
	  response; this will necessarily include the validation steps listed in the
	  specification for the OAuth Access Token Type used.  However, additional
	  validation steps may be needed, depending on the particular application
	  protocol making use of SASL.  In particular, values included as kvpairs in
	  the client response (such as host and port) that correspond to values
	  known to the application server by some other mechanism (such as an application
	  protocol data unit or preconfigured values) MUST be validated to match
	  between the initial client response and the other source(s) of such
	  information.  As a concrete example, when SASL is used over IMAP to an IMAP 
	  server for a single domain, the hostname can be available via configuration;
	  this hostname must be validated to match the value sent in the 'host'
	  kvpair.
	</t>

        <t>The server responds to a successfully verified client message by completing the SASL
        negotiation. The authenticated identity reported by the SASL mechanism is the
   	identity securely established for the client with
   	the OAuth credential.  The application, not the SASL mechanism, based on local
	access policy determines whether the identity reported by the mechanism 
	is allowed access to the requested resource.  Note that the semantics of the 
	authzid are specified by the SASL framework <xref target="RFC4422"/>.</t>
        
          <section title="OAuth Identifiers in the SASL Context">
          
          <t>In the OAuth framework, the client may be authenticated by the authorization server, 
		and the resource owner is authenticated to the authorization server. OAuth access 
		tokens may contain information about the authentication of the resource owner and 
		about the client and may therefore make this information accessible to the resource server.</t>
          		
		<t>If both identifiers
		are needed by an application the developer will need to provide a way to 
		communicate that from the SASL mechanism back to the application.
	     </t>
           </section>
      <section title="Server Response to Failed Authentication">

	<t>For a failed authentication, the server returns an error result in JSON <xref target="RFC7159"/> 
	format and fails the authentication.  The error result consists 
	of the following values:

	<list><t>
          <list style="hanging">
            <t hangText="status (REQUIRED):">The authorization error code. Valid error codes are
				  defined in the IANA "OAuth Extensions Error Registry"
				  as specified in the OAuth 2.0 core specification. 
            </t>

	    <t hangText="scope (OPTIONAL):">An OAuth scope that is valid to access the service. 
				This may be omitted, which implies that unscoped tokens are required.
				If a scope is specified, then a single scope is preferred. At the time 
				this document was written, there are several implementations that do 
				not properly support space-separated lists of scopes, so the use of 
				a space-separated list of scopes is NOT RECOMMENDED.
                  </t>

	    <t hangText="openid-configuration (OPTIONAL):">The URL for a document following the 
	    OpenID Provider Configuration Information schema as described in 
	    OIDCD <xref target="OpenID.Discovery" />, Section 3 that is appropriate for the user.  
	    As specified in OIDCD, this will have the "https" URL scheme. This document 
	    MUST have all OAuth-related data elements populated.  The server MAY return different URLs 
	    for users in different domains, and the client SHOULD NOT cache a single returned value and 
	    assume it applies for all users/domains that the server supports. 
	    The returned discovery document SHOULD have all data
	    elements required by the OpenID Connect Discovery specification
	    populated.  In addition, the discovery document SHOULD contain
	    the 'registration_endpoint' element to identify the endpoint
	    to be used with the Dynamic Client Registration protocol
	    <xref target="RFC7591"/> to obtain the minimum number of
	    parameters necessary for the OAuth protocol exchange to
	    function.  Another comparable discovery or client registration
	    mechanism MAY be used if available.
                  </t>
                  <t>
	    The use of the 'offline_access' scope, as defined in
	    <xref target="OpenID.Core"/>, is RECOMMENDED to give clients the capability to
	    explicitly request a refresh token.
                  </t>
          </list>
        </t></list>
    </t>


    <t>If the resource server provides a scope, then the client MUST always request scoped
	tokens from the token endpoint.  If the resource server does not return a scope, 
	the client SHOULD presume an unscoped token is required to access the resource.
    </t>

    <t>
      Since clients may interact with a number of application servers,
      such as email servers and Extensible Messaging and Presence Protocol (XMPP)
      <xref target="RFC6120"/> servers, they need to have a way
      to determine whether dynamic client registration has been performed
      already and whether an already available refresh token can be
      reused to obtain an access token for the desired resource server.
      This specification RECOMMENDS that a client uses the information in
      the 'iss' element defined in OpenID Connect Core <xref target="OpenID.Core"/> 
      to make this determination.
    </t>
 
      </section>
      <section title="Completing an Error Message Sequence">
	<t>Section 3.6 of SASL <xref target="RFC4422"/> explicitly prohibits additional information
  	in an unsuccessful authentication outcome.  Therefore, the error
  	message is sent in a normal message.  The client MUST then send either an
  	additional client response consisting of a single %x01 (control A) character to 
	the server in order to allow the server to finish the exchange or a SASL 
	abort message as generally defined in Section 3.5 of SASL <xref target="RFC4422"/>.
	A specific example of an abort message is the "BAD" response to an AUTHENTICATE in IMAP <xref target="RFC3501"/>, 
	Section 6.2.2.
	</t>
      </section>

 </section>

      <section anchor="keyed-digests" title="OAuth Access Token Types using Keyed Message Digests">
<t>
OAuth Access Token Types may use keyed message digests, and the client and the resource server may need to perform a cryptographic computation for integrity protection and data origin authentication.</t>

<t>OAuth is designed for access to resources identified by URIs.  SASL is designed for user authentication and
   has no facility for more fine-grained access control.  In this specification, we require or
          define default values for the data elements from an HTTP request that allows the
	  signature base string to be constructed properly.

          The default HTTP path is "/", and the default post body is empty.  These atoms are 
	  defined as extension points so
          that no changes are needed if there is a revision of SASL that supports more
          specific resource authorization, e.g., IMAP access to a specific folder or FTP access
          limited to a specific directory. </t>

        <t>Using the example in the OAuth 1.0a specification as a starting point,
below is the authorization request in OAuth 1.0a style (with %x01 shown
as ^A and line breaks added for readability), assuming it is on an IMAP
server running on port 143:
	</t>

<figure>
            <artwork><![CDATA[
n,a=user@example.com,^A
host=example.com^A
port=143^A
auth=OAuth realm="Example",
           oauth_consumer_key="9djdj82h48djs9d2",
           oauth_token="kkk9d7dh3k39sjv7",
           oauth_signature_method="HMAC-SHA1",
           oauth_timestamp="137131201",
           oauth_nonce="7d8f3e4a",
           oauth_signature="Tm90IGEgcmVhbCBzaWduYXR1cmU"^A^A
]]></artwork>
          </figure>

        <t>The signature base string would be constructed per the OAuth 1.0a 
	specification <xref target="RFC5849" /> with the following things noted:
	<list style="symbols">
		<t>The method value is defaulted to POST.</t>
		<t>The scheme defaults to be "http", and any port number other than 80 is included.</t>
		<t>The path defaults to "/".</t>
		<t>The query string defaults to "".</t>
	</list>
	In this example, the signature base string with line breaks added for 
	readability would be:
	</t>
	<figure> 
            <artwork><![CDATA[
POST&http%3A%2F%2Fexample.com:143%2F&oauth_consumer_key%3D9djdj82h4
8djs9d2%26oauth_nonce%3D7d8f3e4a%26oauth_signature_method%3DHMAC-SH
A1%26oauth_timestamp%3D137131201%26oauth_token%3Dkkk9d7dh3k39sjv7
]]></artwork>
          </figure>

      </section>
      

    </section>

    <section title="Examples">
      <t>These examples illustrate exchanges between IMAP and SMTP clients and servers.  All
         IMAP examples use SASL-IR  <xref target="RFC4959"/> and send payload in the initial 
         client response.   The bearer token examples assume encrypted transport; if the 
         underlying connection is not already TLS, then STARTTLS MUST be used as TLS is required in the 
         bearer token specification. </t>

      <t>Note to implementers:  The SASL OAuth method names are case insensitive.  One example
	uses "Bearer" but that could as easily be "bearer", "BEARER", or "BeArEr".
	</t>

      <section title="Successful Bearer Token Exchange">

        <t>This example shows a successful OAuth 2.0 bearer token exchange in IMAP. Note that line 
	breaks are inserted for readability.</t>

          <figure>
            <artwork><![CDATA[
[Initial connection and TLS establishment...]
S: * OK IMAP4rev1 Server Ready
C: t0 CAPABILITY
S: * CAPABILITY IMAP4rev1 AUTH=OAUTHBEARER SASL-IR
S: t0 OK Completed
C: t1 AUTHENTICATE OAUTHBEARER bixhPXVzZXJAZXhhbXBsZS5jb20sAWhv
      c3Q9c2VydmVyLmV4YW1wbGUuY29tAXBvcnQ9MTQzAWF1dGg9QmVhcmVyI
      HZGOWRmdDRxbVRjMk52YjNSbGNrQmhiSFJoZG1semRHRXVZMjl0Q2c9PQ
      EB
S: t1 OK SASL authentication succeeded
]]></artwork>
          </figure>

        <t>As required by IMAP <xref target="RFC3501"/>, the payloads are base64 encoded. The
          decoded initial client response (with %x01 represented as ^A and long lines
          wrapped for readability) is: 
	</t>
	<figure>
            <artwork><![CDATA[
n,a=user@example.com,^Ahost=server.example.com^Aport=143^A
auth=Bearer vF9dft4qmTc2Nvb3RlckBhbHRhdmlzdGEuY29tCg==^A^A
]]></artwork>
          </figure>

        <t>The same credential used in an SMTP exchange is shown below.
	Again, this example assumes that TLS is already established per the bearer token 
	specification requirements.</t>

          <figure>
            <artwork><![CDATA[
[connection begins]
S: 220 mx.example.com ESMTP 12sm2095603fks.9
C: EHLO sender.example.com
S: 250-mx.example.com at your service,[172.31.135.47]
S: 250-SIZE 35651584
S: 250-8BITMIME
S: 250-AUTH LOGIN PLAIN OAUTHBEARER 
S: 250-ENHANCEDSTATUSCODES
S: 250-STARTTLS
S: 250 PIPELINING
[Negotiate TLS...]
C: t1 AUTH OAUTHBEARER bixhPXVzZXJAZXhhbXBsZS5jb20sAWhvc3Q9c2Vy
      dmVyLmV4YW1wbGUuY29tAXBvcnQ9NTg3AWF1dGg9QmVhcmVyIHZGOWRmd
      DRxbVRjMk52YjNSbGNrQmhiSFJoZG1semRHRXVZMjl0Q2c9PQEB
S: 235 Authentication successful.
[connection continues...]
          ]]></artwork>
          </figure>
	  <t>The decoded initial client response is:</t>
	<figure>
            <artwork><![CDATA[
n,a=user@example.com,^Ahost=server.example.com^Aport=587^A
auth=Bearer vF9dft4qmTc2Nvb3RlckBhbHRhdmlzdGEuY29tCg==^A^A
]]></artwork>
          </figure>


      </section>


      <section title="Successful OAuth 1.0a Token Exchange">
        <t>This IMAP example shows a successful OAuth 1.0a token exchange. Note 
	that line breaks are inserted for readability.  This example assumes that 
	TLS is already established. Signature computation is discussed in 
	<xref target="keyed-digests" />.</t>

          <figure>
            <artwork><![CDATA[
S: * OK IMAP4rev1 Server Ready
C: t0 CAPABILITY
S: * CAPABILITY IMAP4rev1 AUTH=OAUTHBEARER AUTH=OAUTH10A SASL-IR 
S: t0 OK Completed 
C: t1 AUTHENTICATE OAUTH10A bixhPXVzZXJAZXhhbXBsZS5jb20sAWhvc3Q9ZXhhb
      XBsZS5jb20BcG9ydD0xNDMBYXV0aD1PQXV0aCByZWFsbT0iRXhhbXBsZSIsb2F1
      dGhfY29uc3VtZXJfa2V5PSI5ZGpkajgyaDQ4ZGpzOWQyIixvYXV0aF90b2tlbj0
      ia2trOWQ3ZGgzazM5c2p2NyIsb2F1dGhfc2lnbmF0dXJlX21ldGhvZD0iSE1BQy
      1TSEExIixvYXV0aF90aW1lc3RhbXA9IjEzNzEzMTIwMSIsb2F1dGhfbm9uY2U9I
      jdkOGYzZTRhIixvYXV0aF9zaWduYXR1cmU9IlRtOTBJR0VnY21WaGJDQnphV2R1
      WVhSMWNtVSUzRCIBAQ==
S: t1 OK SASL authentication succeeded
]]></artwork>
          </figure>

        <t>As required by IMAP <xref target="RFC3501"/>, the payloads are
      base64 encoded. The
          decoded initial client response (with %x01 represented as ^A and lines
          wrapped for readability) is: </t>

          <figure>
            <artwork><![CDATA[
n,a=user@example.com,^A
host=example.com^A
port=143^A
auth=OAuth realm="Example",
           oauth_consumer_key="9djdj82h48djs9d2",
           oauth_token="kkk9d7dh3k39sjv7",
           oauth_signature_method="HMAC-SHA1",
           oauth_timestamp="137131201",
           oauth_nonce="7d8f3e4a",
           oauth_signature="SSdtIGEgbGl0dGxlIHRlYSBwb3Qu"^A^A
]]></artwork>
          </figure>

      </section>


      <section title="Failed Exchange">
        <t>This IMAP example shows a failed exchange because of the empty Authorization header, which is
          how a client can query for the needed scope. Note that line breaks are inserted for
          readability.</t>

          <figure>
            <artwork><![CDATA[
S: * OK IMAP4rev1 Server Ready
C: t0 CAPABILITY
S: * CAPABILITY IMAP4rev1 AUTH=OAUTHBEARER SASL-IR 
S: t0 OK Completed 
C: t1 AUTHENTICATE OAUTHBEARER bixhPXVzZXJAZXhhbXBsZS5jb20sAW
      hvc3Q9c2VydmVyLmV4YW1wbGUuY29tAXBvcnQ9MTQzAWF1dGg9AQE=
S: + eyJzdGF0dXMiOiJpbnZhbGlkX3Rva2VuIiwic2NvcGUiOiJleGFtcGxl
     X3Njb3BlIiwib3BlbmlkLWNvbmZpZ3VyYXRpb24iOiJodHRwczovL2V4
     YW1wbGUuY29tLy53ZWxsLWtub3duL29wZW5pZC1jb25maWd1cmF0aW9u
     In0=
C: AQ==
S: t1 NO SASL authentication failed
]]></artwork>
          </figure>

        <t> The decoded initial client response is: </t>

          <figure>
            <artwork><![CDATA[
n,a=user@example.com,^Ahost=server.example.com^A
port=143^Aauth=^A^A
            ]]></artwork>
          </figure>

        <t> The decoded server error response is: </t>

          <figure>
            <artwork><![CDATA[
{
"status":"invalid_token",
"scope":"example_scope",
"openid-configuration":"https://example.com/.well-known/openid-config"
}
            ]]></artwork>
          </figure>

        <t>The client responds with the required dummy response; "AQ==" 
        is the base64 encoding of the ASCII value 0x01.  
	The same exchange using the IMAP-specific method of canceling an 
	AUTHENTICATE command sends "*" and is shown below. 
	</t>

          <figure>
            <artwork><![CDATA[
S: * OK IMAP4rev1 Server Ready
C: t0 CAPABILITY
S: * CAPABILITY IMAP4rev1 AUTH=OAUTHBEARER SASL-IR IMAP4rev1
S: t0 OK Completed 
C: t1 AUTHENTICATE OAUTHBEARER bixhPXVzZXJAZXhhbXBsZS5jb20sAW
     hvc3Q9c2VydmVyLmV4YW1wbGUuY29tAXBvcnQ9MTQzAWF1dGg9AQE=
S: + eyJzdGF0dXMiOiJpbnZhbGlkX3Rva2VuIiwic2NvcGUiOiJleGFtcGxl
     X3Njb3BlIiwib3BlbmlkLWNvbmZpZ3VyYXRpb24iOiJodHRwczovL2V4
     YW1wbGUuY29tLy53ZWxsLWtub3duL29wZW5pZC1jb25maWd1cmF0aW9u
     In0=
C: *
S: t1 NO SASL authentication failed
]]></artwork>
          </figure>

      </section>


      <section title="SMTP Example of a Failed Negotiation">
        <t>This example shows an authorization failure in an SMTP exchange.  
	TLS negotiation is not shown, but as noted above, it is required for the use
	of bearer tokens.</t>

          <figure>
            <artwork><![CDATA[
[connection begins]
S: 220 mx.example.com ESMTP 12sm2095603fks.9
C: EHLO sender.example.com
S: 250-mx.example.com at your service,[172.31.135.47]
S: 250-SIZE 35651584
S: 250-8BITMIME
S: 250-AUTH LOGIN PLAIN OAUTHBEARER
S: 250-ENHANCEDSTATUSCODES
S: 250 PIPELINING
[Negotiate TLS...]
C: AUTH OAUTHBEARER bix1c2VyPXNvbWV1c2VyQGV4YW1wbGUuY29tLAFhdXRoPUJlYXJl
       ciB2RjlkZnQ0cW1UYzJOdmIzUmxja0JoZEhSaGRtbHpkR0V1WTI5dENnPT0BAQ==
S: 334 eyJzdGF0dXMiOiJpbnZhbGlkX3Rva2VuIiwic2NoZW1lcyI6ImJlYXJlciBtYWMiL
       CJzY29wZSI6Imh0dHBzOi8vbWFpbC5leGFtcGxlLmNvbS8ifQ==
C: AQ==
S: 535-5.7.1 Username and Password not accepted. Learn more at
S: 535 5.7.1 http://support.example.com/mail/oauth
[connection continues...]
            ]]></artwork>
          </figure>
	  <t>The initial client response is:</t>

          <figure>
            <artwork><![CDATA[
n,user=someuser@example.com,^A
auth=Bearer vF9dft4qmTc2Nvb3RlckBhdHRhdmlzdGEuY29tCg==^A^A
            ]]></artwork>
          </figure>

        <t>The server returned an error message in the 334 SASL message; the
	client responds with the required dummy response, and 
	the server finalizes the negotiation.
	</t>

          <figure>
            <artwork><![CDATA[
{
    "status":"invalid_token",
    "schemes":"bearer mac",
    "scope":"https://mail.example.com/"
}
            ]]></artwork>
          </figure>

      </section>

   

    </section>

   

    <section title="Security Considerations">
    
    <t>OAuth 1.0a and OAuth 2.0 allow for a variety of deployment scenarios, and the security
 properties of these profiles vary. As shown in <xref target="overview"/>, this specification is aimed to be integrated into a larger OAuth deployment. Application developers therefore need to understand their security requirements based on a threat assessment before selecting a specific SASL OAuth mechanism. For OAuth 2.0, a detailed security document <xref target="RFC6819"/> provides guidance to select those OAuth 2.0 components that help to mitigate threats for a given deployment. For OAuth 1.0a, Section 4 of <xref target="RFC5849"/> provides guidance specific to OAuth 1.0a.</t>

   <t>This document specifies two SASL  Mechanisms for OAuth and each comes with different security properties. 
   
   <list style="hanging">
	  <t hangText="OAUTHBEARER:">This mechanism borrows from OAuth 2.0 bearer tokens <xref target="RFC6750"/>. It relies on the application using TLS to protect the OAuth 2.0 bearer token exchange; without TLS usage at the application layer, this method is completely insecure. Consequently, TLS MUST be provided by the application when choosing this authentication mechanism.</t>
	  
	  <t hangText="OAUTH10A:">This mechanism reuses OAuth 1.0a MAC tokens (using the HMAC-SHA1 keyed message digest), as described in Section 3.4.2 of <xref target="RFC5849"/>. To compute the keyed message digest in the same way as in RFC 5839, this specification conveys additional parameters between the client and the server. This SASL mechanism only supports client authentication. If server-side authentication is desirable, then it must be provided by the application underneath the SASL layer. The use of TLS is strongly RECOMMENDED. 
	     </t>
	</list>
	</t>
	
	<t>Additionally, the following aspects are worth pointing out:  
	
	<list style="hanging"> 
	  <t hangText="An access token is not equivalent to the user's long term password."><vspace blankLines="1"/> 
	  
	  Care has to be
   taken when these OAuth credentials are used for actions like changing
   passwords (as it is possible with some protocols, e.g., XMPP <xref target="RFC6120"/>). The
   resource server should ensure that actions taken in the authenticated channel
   are appropriate to the strength of the presented credential.</t>
	  
	  <t hangText="Lifetime of the application sessions."><vspace blankLines="1"/> 
	  It is possible that 
	  SASL will be used to authenticate a connection, and the
   life of that connection may outlast the life of the access token used
   to establish it.  This is a common problem in application protocols
   where connections are long lived and not a problem with this
   mechanism, per se. Resource servers may unilaterally disconnect clients in
   accordance with the application protocol.</t>


   <t hangText="Access tokens have a lifetime."><vspace blankLines="1"/> 
   Reducing the lifetime of an access
   token provides security benefits, and OAuth 2.0 introduces refresh
   tokens to obtain new access tokens on the fly without any need for human interaction. 
    Additionally, a previously obtained access token might be revoked or rendered invalid
   at any time. The client MAY request a new access token for each
   connection to a resource server, but it SHOULD cache and reuse
   valid credentials.</t>

	</list> 
	</t>
	
    </section>
    
    
     <section title="Internationalization Considerations">
	     <t>The identifier asserted by the OAuth authorization server about the resource owner inside the access token may be displayed to a human. For example, when SASL is used in the context of IMAP, the client may assert the resource owner's email address to the IMAP server for usage in an email-based application. The identifier may therefore contain internationalized characters, and an application needs to ensure that the mapping between the identifier provided by OAuth is suitable for use with the application-layer protocol SASL is incorporated into. An example of a SASL-compatible container is the JSON Web Token (JWT) <xref target="RFC7519"/>, which provides a standardized format for exchanging authorization and identity information that supports internationalized characters.</t>  
  
    </section>


    <section title="IANA Considerations">
     <section title="SASL Registration">
      <t> The IANA has registered the following entry in the SASL Mechanisms registry: <list style="empty">
          <t>SASL mechanism name: OAUTHBEARER</t>
          <t>Security Considerations: See this document</t>
          <t>Published Specification: See this document</t>
          <t>For further information: Contact the authors of this document.</t>
	  <t>Intended usage: COMMON</t>
          <t>Owner/Change controller: the IESG</t>
          <t>Note: None</t>
        </list>
      </t>
      <t> The IANA has registered the following entry in the SASL Mechanisms registry: <list style="empty">
          <t>SASL mechanism name: OAUTH10A</t>
          <t>Security Considerations: See this document</t>
          <t>Published Specification: See this document</t>
          <t>For further information: Contact the authors of this document.</t>
	  <t>Intended usage: COMMON</t>
          <t>Owner/Change controller: the IESG</t>
          <t>Note: None</t>
        </list>
      </t>
     </section>
   

    </section>

  </middle>

  <back>

    <references title="Normative References">
<?rfc include="reference.RFC.2119"?>
      <?rfc include='reference.RFC.4422.xml' ?>
      <?rfc include='reference.RFC.5234.xml' ?>
      <?rfc include='reference.RFC.5246.xml' ?>
      <?rfc include='reference.RFC.5849.xml' ?>
      <?rfc include='reference.RFC.5801.xml' ?>
      <?rfc include='reference.RFC.4648.xml' ?>
      <?rfc include='reference.RFC.6749.xml' ?>
      <?rfc include='reference.RFC.6750.xml' ?>
      <?rfc include='reference.RFC.7159.xml' ?>

<!-- draft-ietf-oauth-dyn-reg now RFC 7591 -->     
 <?rfc include='reference.RFC.7591.xml' ?>

<reference anchor="OpenID.Discovery" target="http://openid.net/specs/openid-connect-discovery-1_0.html">
        <front>
          <title>OpenID Connect Discovery 1.0</title>

          <author fullname="Nat Sakimura" initials="N." surname="Sakimura">
            <organization abbrev="NRI">Nomura Research Institute,
            Ltd.</organization>
          </author>

          <author fullname="John Bradley" initials="J." surname="Bradley">
            <organization abbrev="Protiviti">Protiviti Government
            Services</organization>
          </author>

          <author fullname="Michael B. Jones" initials="M.B." surname="Jones">
            <organization abbrev="Microsoft">Microsoft</organization>
          </author>

          <author fullname="Edmund Jay" initials="E." surname="Jay">
            <organization abbrev="MGI1">MGI1</organization>
          </author>

          <date month="November" year="2014" />
        </front>

      </reference>

      <reference anchor="OpenID.Core" target="http://openid.net/specs/openid-connect-core-1_0.html">
        <front>
          <title>OpenID Connect Core 1.0</title>

          <author fullname="Nat Sakimura" initials="N." surname="Sakimura">
            <organization abbrev="NRI">Nomura Research Institute, Ltd.</organization>
          </author>

          <author fullname="John Bradley" initials="J." surname="Bradley">
            <organization abbrev="Ping Identity">Ping Identity</organization>
          </author>

          <author fullname="Michael B. Jones" initials="M.B." surname="Jones">
            <organization abbrev="Microsoft">Microsoft</organization>
          </author>

          <author fullname="Breno de Medeiros" initials="B." surname="de Medeiros">
            <organization abbrev="Google">Google</organization>
          </author>

	  <author fullname="Chuck Mortimore" initials="C." surname="Mortimore">
	    <organization abbrev="Salesforce">Salesforce</organization>
	  </author>

          <date month="November" year="2014"/>
        </front>

      </reference>


    </references>

    <references title="Informative References">
      <?rfc include='reference.RFC.3501.xml' ?>
      <?rfc include='reference.RFC.4959.xml' ?>
      <?rfc include='reference.RFC.5321.xml' ?>
      <?rfc include='reference.RFC.6120.xml' ?>
      <?rfc include='reference.RFC.6819.xml' ?>
      <?rfc include='reference.RFC.7033.xml' ?>
      <?rfc include='reference.RFC.7230.xml' ?>

<!-- draft-ietf-oauth-json-web-token now RFC 7519 -->
<?rfc include='reference.RFC.7519.xml' ?>


    </references>

    <section  title='Acknowledgements' numbered='no'>
	<t>
	The authors would like to thank the members of the KITTEN working group and in 
	addition and specifically: Simon Josefson, Torsten Lodderstadt, Ryan Troll, Alexey Melnikov, 
	Jeffrey Hutzelman, Nico Williams, Matt Miller, and Benjamin Kaduk.
	</t>
	<t>
   This document was produced under the chairmanship of Alexey Melnikov, Tom Yu, Shawn Emery, Josh Howlett, Sam Hartman, Matthew Miller, and Benjamin Kaduk. The supervising Area Director was Stephen Farrell.
   </t>
    </section>

  </back>
</rfc>
