<p>Automatic reconnection after spurious disconnection is a must-have feature in modern IM applications. One way of providing this feature is storing user login information on disk for reuse. However, plaintext storage of passwords is inherently insecure, while protecting the XMPP password with a master-password is inconvenient for the end-user. With a token-based authentication mechanism, the user only has to provide login information once, for the initial connection to the XMPP server, and can later rely on the application's automatic use of tokens for subsequent reconnections.</p>
<p>Moreover, while reconnecting to the XMPP server, the client usually has to go through the same long process of SASL challenge-response exchange which may lead to a noticably long reconnection time, especially while using SCRAM-based mechanisms. Providing a token to the XMPP server is both secure and doesn't require multiple challenge-response roundtrips, therefore might significantly speed up reconnection times.</p>
<p>This extension requires the client application to authenticate to the XMPP server using a regular XMPP authentication mechanism like SCRAM-SHA-1 at least once. After that, the following authentications may be done using X-OAUTH SASL mechanism with a token obtained from the server.</p>
<tr><td>Access token</td><td>These are short lived tokens whose grants aren't
tracked by the server (i.e. there's no need to store anything in a database).
Access tokens can be used as a payload for the X-OAUTH authentication mechanism
and grant access to the system.
Access tokens can't be revoked.
An access token is valid only until its expiry date is reached.</td></tr>
<tr><td>Refresh token</td><td>These are longer lived tokens which are tracked by the server,
therefore require persistent storage.
Refresh tokens can be used as a payload for the X-OAUTH authentication mechanism
and grant access to the system, as well as result in a new set of tokens being
returned upon successful authentication.
Refresh tokens can be revoked.
A refresh token is valid until it has expired, unless it has been revoked.
On revocation, it immediately becomes invalid.
As the server stores information about granted tokens, it can also
persistently mark them as revoked.</td></tr>
</table>
<p>While only two token types have been described above, implementations might use other token types for specific purposes. For example, a particular token type could limit the access privileges of a user logged into the system or denote an affiliation with a Multi User Chat room. None of such capability grants are subject of this specification, though.</p>
<p><strong>This section is informal.</strong> The token formats described below are used in one of the experimental implementations, but are not proposed as standard. If such a standard turns out to be required, then <linkurl="http://jwt.io/">JSON Web Tokens</link> might be a viable format to adopt.</p>
<p>All tokens are exchanged as Base64 encoded binary data. Serialization format of the token before encoding with Base64 is dependent on its type. Common parts in every token are <tt>BARE_JID</tt> and <tt>EXPIRES_AT</tt>. <tt>EXPIRES_AT</tt> is a timestamp saying when given token will expire. <tt>\0</tt> stands for the ASCII null character (i.e. byte 0). Text in single quotes (<tt>'example'</tt>) is literal. <tt>ALL_CAPS</tt> denote parameters.</p>
<section2topic="Obtaining a token"anchor="obtaining_token">
<p>After authentication with some other mechanism like SCRAM-SHA-1, a client may request a token from the server by sending following iq get to its own bare JID:</p>