GT2/GT2-Android/node_modules/auth0/docs/management_ManagementTokenP...

197 lines
37 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>management/ManagementTokenProvider.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="module-auth.AuthenticationClient.html">AuthenticationClient</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.AuthenticationClient.html#changePassword">changePassword</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.AuthenticationClient.html#clientCredentialsGrant">clientCredentialsGrant</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.AuthenticationClient.html#getClientInfo">getClientInfo</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.AuthenticationClient.html#getDelegationToken">getDelegationToken</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.AuthenticationClient.html#getProfile">getProfile</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.AuthenticationClient.html#passwordGrant">passwordGrant</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.AuthenticationClient.html#requestChangePasswordEmail">requestChangePasswordEmail</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.AuthenticationClient.html#requestEmailCode">requestEmailCode</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.AuthenticationClient.html#requestMagicLink">requestMagicLink</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.AuthenticationClient.html#requestSMSCode">requestSMSCode</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.AuthenticationClient.html#verifySMSCode">verifySMSCode</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="module-auth.DatabaseAuthenticator.html">DatabaseAuthenticator</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.DatabaseAuthenticator.html#changePassword">changePassword</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.DatabaseAuthenticator.html#requestChangePasswordEmail">requestChangePasswordEmail</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.DatabaseAuthenticator.html#signIn">signIn</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.DatabaseAuthenticator.html#signUp">signUp</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="module-auth.OAuthAuthenticator.html">OAuthAuthenticator</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.OAuthAuthenticator.html#passwordGrant">passwordGrant</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.OAuthAuthenticator.html#signIn">signIn</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-auth.OAuthAuthenticator.html#socialSignIn">s
</nav>
<div id="main">
<h1 class="page-title">management/ManagementTokenProvider.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>var ArgumentError = require('rest-facade').ArgumentError;
var assign = Object.assign || require('object.assign');
var AuthenticationClient = require('../auth');
var memoizer = require('lru-memoizer');
var Promise = require('bluebird');
var DEFAULT_OPTIONS = { enableCache: true };
/**
* @class ManagementTokenProvider
* Auth0 Management API Token Provider.
* @constructor
* @memberOf module:management
*
* @param {Object} options Options for the ManagementTokenProvider.
* @param {String} options.domain ManagementClient server domain.
* @param {String} options.clientId Non Interactive Client Id.
* @param {String} options.clientSecret Non Interactive Client Secret.
* @param {String} options.scope Non Interactive Client Scope.
* @param {String} options.audience Audience of the Management API.
* @param {Boolean} [options.enableCache=true] Enabled or Disable Cache
* @param {Number} [options.cacheTTLInSeconds] By default the `expires_in` value will be used to determine the cached time of the token, this can be overridden.
*/
var ManagementTokenProvider = function (options) {
if (!options || typeof options !== 'object') {
throw new ArgumentError('Options must be an object');
}
var params = assign({}, DEFAULT_OPTIONS, options);
if (!params.domain || params.domain.length === 0) {
throw new ArgumentError('Must provide a domain');
}
if (!params.clientId || params.clientId.length === 0) {
throw new ArgumentError('Must provide a clientId');
}
if (!params.clientSecret || params.clientSecret.length === 0) {
throw new ArgumentError('Must provide a clientSecret');
}
if (!params.audience || params.audience.length === 0) {
throw new ArgumentError('Must provide a audience');
}
if (typeof params.enableCache !== 'boolean'){
throw new ArgumentError('enableCache must be a boolean');
}
if (params.enableCache &amp;&amp; params.cacheTTLInSeconds) {
if (typeof params.cacheTTLInSeconds !== 'number') {
throw new ArgumentError('cacheTTLInSeconds must be a number');
}
if (params.cacheTTLInSeconds &lt;= 0) {
throw new ArgumentError('cacheTTLInSeconds must be a greater than 0');
}
}
if (params.scope &amp;&amp; typeof params.scope !== 'string'){
throw new ArgumentError('scope must be a string');
}
this.options = params;
var authenticationClientOptions = {
domain: this.options.domain,
clientId: this.options.clientId,
clientSecret: this.options.clientSecret,
telemetry: this.options.telemetry
};
this.authenticationClient = new AuthenticationClient(authenticationClientOptions);
}
/**
* Returns the access_token.
*
* @method getAccessToken
* @memberOf module:management.ManagementTokenProvider.prototype
*
* @return {Promise} Promise returning an access_token.
*/
ManagementTokenProvider.prototype.getAccessToken = function () {
if(this.options.enableCache){
return this.getCachedAccessToken(this.options)
.then(function (data) {
return data.access_token
});
}else{
return this.clientCredentialsGrant(this.options.domain, this.options.scope, this.options.audience)
.then(function (data) {
return data.access_token
});
}
}
ManagementTokenProvider.prototype.getCachedAccessToken = Promise.promisify(
memoizer({
load: function (options, callback) {
this.clientCredentialsGrant(options.domain, options.scope, options.audience)
.then(function (data) {
callback(null, data);
})
.catch(function (err) {
callback(err);
});
},
hash: function (options) {
return options.domain + '-' + options.clientId + '-' + options.scope;
},
itemMaxAge: function (options, data) {
if(options.cacheTTLInSeconds){
return options.cacheTTLInSeconds * 1000;
}
// if the expires_in is lower than 10 seconds, do not subtract 10 additional seconds.
if (data.expires_in &amp;&amp; data.expires_in &lt; 10 /* seconds */){
return data.expires_in * 1000;
}else if(data.expires_in){
// Subtract 10 seconds from expires_in to fetch a new one, before it expires.
return data.expires_in * 1000 - 10000 /* milliseconds */;
}
return 60 * 60 * 1000; //1h
},
max: 100
})
);
ManagementTokenProvider.prototype.clientCredentialsGrant = function (domain, scope, audience) {
return this.authenticationClient.clientCredentialsGrant({
audience: audience,
scope: scope
});
};
module.exports = ManagementTokenProvider;
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Fri Dec 08 2017 10:01:22 GMT-0300 (-03) using the Minami theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>