UNPKG

react-native-azure-auth-encrypted

Version:

Azure AD authentication in React Native using encrypted storage

169 lines (137 loc) 8.85 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>token/scope.js - 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">token/scope.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>const BASIC_SCOPE = 'offline_access openid profile' /** * Azure AD Auth scope representation class * * 1. Remove MS Graph URLs from scope, as it is default for any scope * 2. Remove eventual commas and double spaces * 3. Sort * 4. BASIC SCOPE is always a part of auth requests * * @namespace TokenCache.Scope * * @param {string | Array&lt;String> | ''} scope - without parameters represents * BASIC_SCOPE = 'offline_access openid profile' * * @memberof TokenCache * @class Scope */ export default class Scope { constructor(scope = '') { if(scope instanceof Scope) { this.scopeStr = scope.scopeStr } else if (typeof scope === 'string') { this.scopeStr = this._refine(scope) } else if (scope.constructor === Array) { this.scopeStr = this._refine(scope.join(' ')) } else { throw new Error('Ivalid constructor parameter in Scope()') } if (this.scopeStr.length == 0) { this.basicScope = true this.scope = [] } else { this.scope = this.scopeStr.split(' ') } } toString() { if (this.basicScope) { return BASIC_SCOPE } return BASIC_SCOPE + ' ' + this.scopeStr } _refine(scope) { // remove standard scopes, that are added to every request let newScope = scope.replace(/openid|profile|offline_access/g, '').toLowerCase() // remove MS Graph URL newScope = newScope.replace(new RegExp('https://graph.microsoft.com/', 'g'), '') // remove double spaces and commas .replace(/,+/g, '').replace(/\s+/g, ' ').trim() // Sort return newScope.split(' ').sort().join(' ') } /** * Check if newScope is a subset of baseScope * * @param {Array} newScope * @param {Array} otherScope * * @returns {boolean} */ isSubsetOf(otherScope) { if (!(otherScope instanceof Scope)) { throw new Error('Parameter is not a Scope() instance') } if (otherScope.basicScope || this.basicScope) { // The condition order here is important! // With the second condition we should only return true if the first one is false return true } let difference = this.scope.filter(x => !otherScope.scope.includes(x)) return difference.length == 0 } /** * Copmare if the current instance scope intersects witt one from parameter * Only NON basic scopes are compared * * @param {Scope} otherScope */ isIntersects(otherScope) { if (!(otherScope instanceof Scope)) { throw new Error('Parameter is not a Scope() instance') } for (const element of this.scope) { if (otherScope.scope.includes(element)) { return true } } return false } equals(other) { if (!(other instanceof Scope)) { throw new Error('Parameter is not a Scope() instance') } return this.toString() === other.toString() } static basicScope() { return new Scope() } }</code></pre> </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>