UNPKG

react-native-azure-auth-encrypted

Version:

Azure AD authentication in React Native using encrypted storage

1,776 lines (566 loc) • 28.1 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>Auth - Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav> <li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Classes</li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Auth.html">Auth</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Auth.html#.acquireTokenSilent">acquireTokenSilent</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Auth.html#.clearPersistenCache">clearPersistenCache</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Auth.html#.exchange">exchange</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Auth.html#.loginUrl">loginUrl</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Auth.html#.logoutUrl">logoutUrl</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Auth.html#.msGraphRequest">msGraphRequest</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Auth.html#.refreshTokens">refreshTokens</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="AzureAuth.html">AzureAuth</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="BaseError.html">BaseError</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Client.html">Client</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TokenCache.AccessTokenItem.html">AccessTokenItem</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TokenCache.BaseTokenItem.html">BaseTokenItem</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TokenCache.RefreshTokenItem.html">RefreshTokenItem</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TokenCache.Scope.html">Scope</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TokenCache.TokenCache.html">TokenCache</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="WebAuth.html">WebAuth</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="WebAuth.html#.authorize">authorize</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="WebAuth.html#.clearSession">clearSession</a></span></li><li class="nav-heading"><a href="global.html">Globals</a></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#getAllUserTokenKeys">getAllUserTokenKeys</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#isIntersects">isIntersects</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#isSubsetOf">isSubsetOf</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#request">request</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#serializeParams">serializeParams</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="global.html#validate">validate</a></span></li> </nav> <div id="main"> <h1 class="page-title">Auth</h1> <section> <header> <h2> Auth </h2> </header> <article> <div class="container-overview"> <div class="section-method"> <h4 class="name" id="Auth"><span class="type-signature"></span>new Auth<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> <p>Azure AD V2 Auth API</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="auth_index.js.html">auth/index.js</a>, <a href="auth_index.js.html#line22">line 22</a> </li></ul></dd> <dt class="tag-see">See:</dt> <dd class="tag-see"> <ul> <li><a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols">https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols</a></li> </ul> </dd> </dl> </div> </div> <h3 class="subsection-title">Methods</h3> <div class="section-method"> <h4 class="name" id=".acquireTokenSilent"><span class="type-signature">(async, static) </span>acquireTokenSilent<span class="signature">(parameters)</span><span class="type-signature"></span></h4> <div class="description"> <p>Try to obtain token silently without user interaction</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="auth_index.js.html">auth/index.js</a>, <a href="auth_index.js.html#line178">line 178</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>parameters</code></td> <td class="type"> <span class="param-type"><code>Object</code></span> </td> <td class="description last"> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>userId</code></td> <td class="type"> <span class="param-type"><code>String</code></span> </td> <td class="description last"> <p>user login name (e.g. from Id token)</p> </td> </tr> <tr> <td class="name"><code>scope</code></td> <td class="type"> <span class="param-type"><code>String</code></span> </td> <td class="description last"> <p>scopes requested for the issued tokens.</p> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </div> <div class="section-method"> <h4 class="name" id=".clearPersistenCache"><span class="type-signature">(async, static) </span>clearPersistenCache<span class="signature">(userId)</span><span class="type-signature"></span></h4> <div class="description"> <p>Clear persystent cache - AsyncStorage - for given client ID and user ID or ALL users</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="auth_index.js.html">auth/index.js</a>, <a href="auth_index.js.html#line249">line 249</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>userId</code></td> <td class="type"> <span class="param-type"><code>String</code></span> </td> <td class="default"> null </td> <td class="description last"> <p>ID of user whose tokens will be cleared/deleted if ommited - tokens for ALL users and current client will be cleared</p> </td> </tr> </tbody> </table> </div> <div class="section-method"> <h4 class="name" id=".exchange"><span class="type-signature">(static) </span>exchange<span class="signature">(input)</span><span class="type-signature"> &rarr; {Promise}</span></h4> <div class="description"> <p>Exchanges a code obtained via <code>/authorize</code> for the access tokens</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="auth_index.js.html">auth/index.js</a>, <a href="auth_index.js.html#line109">line 109</a> </li></ul></dd> <dt class="tag-see">See:</dt> <dd class="tag-see"> <ul> <li><a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols-oauth-code#request-an-access-token">https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols-oauth-code#request-an-access-token</a></li> </ul> </dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>input</code></td> <td class="type"> <span class="param-type"><code>Object</code></span> </td> <td class="description last"> <p>input used to obtain tokens from a code</p> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>code</code></td> <td class="type"> <span class="param-type"><code>String</code></span> </td> <td class="description last"> <p>code returned by <code>/authorize</code>.</p> </td> </tr> <tr> <td class="name"><code>redirectUri</code></td> <td class="type"> <span class="param-type"><code>String</code></span> </td> <td class="description last"> <p>original redirectUri used when calling <code>/authorize</code>.</p> </td> </tr> <tr> <td class="name"><code>scope</code></td> <td class="type"> <span class="param-type"><code>String</code></span> </td> <td class="description last"> <p>A space-separated list of scopes. The scopes requested in this leg must be equivalent to or a subset of the scopes requested in the first leg</p> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <div class="section-returns"> <h5>Returns:</h5> <dl class="param-type"> <dt> Type: </dt> <dd> <span class="param-type"><code>Promise</code></span> </dd> </dl> </div> </div> <div class="section-method"> <h4 class="name" id=".loginUrl"><span class="type-signature">(static) </span>loginUrl<span class="signature">(parameters)</span><span class="type-signature"> &rarr; {String}</span></h4> <div class="description"> <p>Builds the full authorize endpoint url in the Authorization Server (AS) with given parameters.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="auth_index.js.html">auth/index.js</a>, <a href="auth_index.js.html#line63">line 63</a> </li></ul></dd> <dt class="tag-see">See:</dt> <dd class="tag-see"> <ul> <li><a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols-oauth-code">https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols-oauth-code</a></li> </ul> </dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>parameters</code></td> <td class="type"> <span class="param-type"><code>Object</code></span> </td> <td class="description last"> <p>parameters to send to <code>/authorize</code></p> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>responseType</code></td> <td class="type"> <span class="param-type"><code>String</code></span> </td> <td class="description last"> <p>type of the response to get from <code>/authorize</code>.</p> </td> </tr> <tr> <td class="name"><code>redirectUri</code></td> <td class="type"> <span class="param-type"><code>String</code></span> </td> <td class="description last"> <p>where the AS will redirect back after success or failure.</p> </td> </tr> <tr> <td class="name"><code>state</code></td> <td class="type"> <span class="param-type"><code>String</code></span> </td> <td class="description last"> <p>random string to prevent CSRF attacks.</p> </td> </tr> <tr> <td class="name"><code>scope</code></td> <td class="type"> <span class="param-type"><code>String</code></span> </td> <td class="description last"> <p>a space-separated list of scopes that you want the user to consent to.</p> </td> </tr> <tr> <td class="name"><code>prompt</code></td> <td class="type"> <span class="param-type"><code>String</code></span> </td> <td class="description last"> <p>(optional) indicates the type of user interaction that is required. The only valid values at this time are 'login', 'none', and 'consent'.</p> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <div class="section-returns"> <h5>Returns:</h5> <dl class="param-type"> <dt> Type: </dt> <dd> <span class="param-type"><code>String</code></span> </dd> </dl> <div class="param-desc"> <p>authorize url with specified parameters to redirect to for AuthZ/AuthN.</p> </div> </div> </div> <div class="section-method"> <h4 class="name" id=".logoutUrl"><span class="type-signature">(static) </span>logoutUrl<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4> <div class="description"> <p>Builds the full logout endpoint url in the Authorization Server (AS) with given parameters. https://login.microsoftonline.com/common/oauth2/logout?post_logout_redirect_uri=[URI]&amp;redirect_uri=[URI]</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="auth_index.js.html">auth/index.js</a>, <a href="auth_index.js.html#line89">line 89</a> </li></ul></dd> </dl> <div class="section-returns"> <h5>Returns:</h5> <dl class="param-type"> <dt> Type: </dt> <dd> <span class="param-type"><code>String</code></span> </dd> </dl> <div class="param-desc"> <p>logout url with default parameter</p> </div> </div> </div> <div class="section-method"> <h4 class="name" id=".msGraphRequest"><span class="type-signature">(static) </span>msGraphRequest<span class="signature">(parameters)</span><span class="type-signature"> &rarr; {Promise}</span></h4> <div class="description"> <p>Return user information using an access token</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="auth_index.js.html">auth/index.js</a>, <a href="auth_index.js.html#line225">line 225</a> </li></ul></dd> <dt class="tag-see">See:</dt> <dd class="tag-see"> <ul> <li><a href="https://developer.microsoft.com/en-us/graph/docs/concepts/overview">https://developer.microsoft.com/en-us/graph/docs/concepts/overview</a></li> <li><a href="https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_get">https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_get</a></li> </ul> </dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>parameters</code></td> <td class="type"> <span class="param-type"><code>Object</code></span> </td> <td class="description last"> <p>user info parameters</p> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>token</code></td> <td class="type"> <span class="param-type"><code>String</code></span> </td> <td class="description last"> <p>user's access token</p> </td> </tr> <tr> <td class="name"><code>path</code></td> <td class="type"> <span class="param-type"><code>String</code></span> </td> <td class="description last"> <p>MS Graph API Path</p> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <div class="section-returns"> <h5>Returns:</h5> <dl class="param-type"> <dt> Type: </dt> <dd> <span class="param-type"><code>Promise</code></span> </dd> </dl> </div> </div> <div class="section-method"> <h4 class="name" id=".refreshTokens"><span class="type-signature">(static) </span>refreshTokens<span class="signature">(parameters)</span><span class="type-signature"> &rarr; {Promise}</span></h4> <div class="description"> <p>Obtain new tokens (access and id) using the Refresh Token obtained during Auth (requesting <code>offline_access</code> scope)</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="auth_index.js.html">auth/index.js</a>, <a href="auth_index.js.html#line140">line 140</a> </li></ul></dd> <dt class="tag-see">See:</dt> <dd class="tag-see"> <ul> <li><a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols-oauth-code#refresh-the-access-token">https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols-oauth-code#refresh-the-access-token</a></li> </ul> </dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>parameters</code></td> <td class="type"> <span class="param-type"><code>Object</code></span> </td> <td class="description last"> <p>refresh token parameters</p> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>refreshToken</code></td> <td class="type"> <span class="param-type"><code>String</code></span> </td> <td class="attributes"> </td> <td class="description last"> <p>user's issued refresh token</p> </td> </tr> <tr> <td class="name"><code>scope</code></td> <td class="type"> <span class="param-type"><code>String</code></span> </td> <td class="attributes"> </td> <td class="description last"> <p>scopes requested for the issued tokens.</p> </td> </tr> <tr> <td class="name"><code>redirectUri</code></td> <td class="type"> <span class="param-type"><code>String</code></span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"> <p>the same redirect_uri value that was used to acquire the authorization_code.</p> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <div class="section-returns"> <h5>Returns:</h5> <dl class="param-type"> <dt> Type: </dt> <dd> <span class="param-type"><code>Promise</code></span> </dd> </dl> </div> </div> </article> </section> </div> <br class="clear"> <footer> Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Tue Sep 09 2025 13:24:03 GMT+0200 (Mitteleuropäische Sommerzeit) using the Minami theme. </footer> <script>prettyPrint();</script> <script src="scripts/linenumber.js"></script> </body> </html>