Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into custom_domains_su…
Browse files Browse the repository at this point in the history
…pport

# Conflicts:
#	src/management/index.js
  • Loading branch information
stevezau committed Nov 11, 2018
2 parents 3c55b54 + 66cca83 commit 0593007
Show file tree
Hide file tree
Showing 7 changed files with 1,046 additions and 11 deletions.
4 changes: 3 additions & 1 deletion docs/management_JobsManager.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ <h1 class="page-title">management/JobsManager.js</h1>
*
* @example
* var params = {
* user_id: '{USER_ID}'
* user_id: '{USER_ID}',
* client_id: '{CLIENT_ID}'
* };
*
* management.jobs.verifyEmail(function (err) {
Expand All @@ -246,6 +247,7 @@ <h1 class="page-title">management/JobsManager.js</h1>
*
* @param {Object} data User data object.
* @param {String} data.user_id ID of the user to be verified.
* @param {String} data.client_id ID of the client for which the verification email will be sent.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
Expand Down
54 changes: 54 additions & 0 deletions src/auth/OAuthAuthenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,60 @@ OAuthAuthenticator.prototype.passwordGrant = function(userData, cb) {
return this.oauthWithIDTokenValidation.create(params, data);
};

/**
* Sign in using a refresh token
*
* @method refreshToken
* @memberOf module:auth.OAuthAuthenticator.prototype
*
* @example <caption>
* Given a refresh token from a previous authentication request
* it will return a JSON with the access_token and id_token.
* More information in the
* <a href="https://auth0.com/docs/api/authentication#refresh-token">
* API Docs
* </a>.
* </caption>
*
* var data = {
* client_id: '{CLIENT_ID}', // Optional field.
* refresh_token: '{REFRESH_TOKEN}',
* };
*
* auth0.oauth.refreshToken(data, function (err, userData) {
* if (err) {
* // Handle error.
* }
*
* console.log(userData);
* });
*
* @param {Object} userData User credentials object.
* @param {String} userData.refresh_token Refresh token.
*
* @return {Promise|undefined}
*/
OAuthAuthenticator.prototype.refreshToken = function(userData, cb) {
var params = {
type: 'token'
};
var defaultFields = {
client_id: this.clientId,
grant_type: 'refresh_token'
};
var data = extend(defaultFields, userData);
if (!userData || typeof userData !== 'object') {
throw new ArgumentError('Missing user data object');
}
if (typeof data.refresh_token !== 'string' || data.refresh_token.split().length === 0) {
throw new ArgumentError('refresh_token is required');
}
if (cb && cb instanceof Function) {
return this.oauthWithIDTokenValidation.create(params, data, cb);
}
return this.oauthWithIDTokenValidation.create(params, data);
};

/**
* Sign in using a social provider access token.
*
Expand Down
35 changes: 35 additions & 0 deletions src/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,4 +543,39 @@ utils.wrapPropertyMethod(
*/
utils.wrapPropertyMethod(AuthenticationClient, 'passwordGrant', 'oauth.passwordGrant');

/**
* Sign in using a refresh token
*
* @method refreshToken
* @memberOf module:auth.AuthenticationClient.prototype
*
* @example <caption>
* Given a refresh token from a previous authentication request,
* it will return a JSON with the access_token and id_token.
* More information in the
* <a href="https://auth0.com/docs/api/authentication#refresh-token">
* API Docs
* </a>.
* </caption>
*
* var data = {
* client_id: '{CLIENT_ID}', // Optional field.
* refresh_token: '{REFRESH_TOKEN}',
* };
*
* auth0.refreshToken(data, function (err, userData) {
* if (err) {
* // Handle error.
* }
*
* console.log(userData);
* });
*
* @param {Object} userData User credentials object.
* @param {String} userData.refresh_token Refresh token.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(AuthenticationClient, 'refreshToken', 'oauth.refreshToken');

module.exports = AuthenticationClient;
197 changes: 189 additions & 8 deletions src/management/GuardianManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var ArgumentError = require('rest-facade').ArgumentError;
var utils = require('../utils');
var Auth0RestClient = require('../Auth0RestClient');
var RetryRestClient = require('../RetryRestClient');

Expand Down Expand Up @@ -49,6 +50,60 @@ var GuardianManager = function(options) {
options.tokenProvider
);
this.enrollments = new RetryRestClient(guardianEnrollmentsAuth0RestClient, options.retry);

/**
* Provides an abstraction layer for retrieving Guardian tickets.
*
* @type {external:RestClient}
*/
var guardianTicketsAuth0RestClient = new Auth0RestClient(
options.baseUrl + '/guardian/enrollments/ticket',
clientOptions,
options.tokenProvider
);
this.tickets = new RetryRestClient(guardianTicketsAuth0RestClient, options.retry);

/**
* Provides an abstraction layer for retrieving Guardian factors.
*
* @type {external:RestClient}
*/
var guardianFactorsAuth0RestClient = new Auth0RestClient(
options.baseUrl + '/guardian/factors/:name',
clientOptions,
options.tokenProvider
);
this.factors = new RetryRestClient(guardianFactorsAuth0RestClient, options.retry);

/**
* Provides an abstraction layer for retrieving Guardian factors.
*
* @type {external:RestClient}
*/
var guardianFactorsTemplatesAuth0RestClient = new Auth0RestClient(
options.baseUrl + '/guardian/factors/:name/templates',
clientOptions,
options.tokenProvider
);
this.factorsTemplates = new RetryRestClient(
guardianFactorsTemplatesAuth0RestClient,
options.retry
);

/**
* Provides an abstraction layer for retrieving Guardian factor providers.
*
* @type {external:RestClient}
*/
var guardianFactorsProvidersAuth0RestClient = new Auth0RestClient(
options.baseUrl + '/guardian/factors/:name/providers/:provider',
clientOptions,
options.tokenProvider
);
this.factorsProviders = new RetryRestClient(
guardianFactorsProvidersAuth0RestClient,
options.retry
);
};

/**
Expand All @@ -58,7 +113,7 @@ var GuardianManager = function(options) {
* @memberOf module:management.GuardianManager.prototype
*
* @example
* management.users.getGuardianEnrollment({ id: ENROLLMENT_ID }, function (err, enrollment) {
* management.guardian.getGuardianEnrollment({ id: ENROLLMENT_ID }, function (err, enrollment) {
* console.log(enrollment);
* });
*
Expand All @@ -68,9 +123,7 @@ var GuardianManager = function(options) {
*
* @return {Promise|undefined}
*/
GuardianManager.prototype.getGuardianEnrollment = function(params, cb) {
return this.enrollments.get(params, cb);
};
utils.wrapPropertyMethod(GuardianManager, 'getGuardianEnrollment', 'enrollments.get');

/**
* Delete a Guardian enrollment.
Expand All @@ -79,7 +132,7 @@ GuardianManager.prototype.getGuardianEnrollment = function(params, cb) {
* @memberOf module:management.GuardianManager.prototype
*
* @example
* management.users.deleteGuardianEnrollment({ id: ENROLLMENT_ID }, function (err, enrollments) {
* management.guardian.deleteGuardianEnrollment({ id: ENROLLMENT_ID }, function (err, enrollments) {
* console.log(enrollments);
* });
*
Expand All @@ -89,8 +142,136 @@ GuardianManager.prototype.getGuardianEnrollment = function(params, cb) {
*
* @return {Promise|undefined}
*/
GuardianManager.prototype.deleteGuardianEnrollment = function(params, cb) {
return this.enrollments.delete(params, cb);
};
utils.wrapPropertyMethod(GuardianManager, 'deleteGuardianEnrollment', 'enrollments.delete');

/**
* Create a Guardian enrollment ticket.
*
* @method createEnrollmentTicket
* @memberOf module:management.GuardianManager.prototype
*
* @example
* management.guardian.createEnrollmentTicket(function (err, ticket) {
* console.log(ticket);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(GuardianManager, 'createEnrollmentTicket', 'tickets.create');

/**
* Get a list of factors and statuses.
*
* @method getFactors
* @memberOf module:management.GuardianManager.prototype
*
* management.guardian.getFactors(function (err, factors) {
* console.log(factors.length);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(GuardianManager, 'getFactors', 'factors.getAll');

/**
* Get Guardian factor provider configuration
*
* @method getFactorProvider
* @memberOf module:management.GuardianManager.prototype
*
* management.guardian.getFactorProvider({ name: 'sms', provider: 'twilio'}, function (err, provider) {
* console.log(provider);
* });
*
* @param {Object} params Factor provider parameters.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(GuardianManager, 'getFactorProvider', 'factorsProviders.get');

/**
* Update Guardian's factor provider
*
* @method updateFactorProvider
* @memberOf module:management.GuardianManager.prototype
*
* management.guardian.updateFactorProvider({ name: 'sms', provider: 'twilio' }, {
* messaging_service_sid: 'XXXXXXXXXXXXXX',
* auth_token: 'XXXXXXXXXXXXXX',
* sid: 'XXXXXXXXXXXXXX'
* }, function(err, provider) {
* console.log(provider);
* });
*
* @param {Object} params Factor provider parameters.
* @param {Object} data Updated Factor provider data.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(GuardianManager, 'updateFactorProvider', 'factorsProviders.update');

/**
* Get Guardian enrollment and verification factor templates
*
* @method getFactorTemplates
* @memberOf module:management.GuardianManager.prototype
*
* management.guardian.getFactorTemplates({ name: 'sms' }, function (err, templates) {
* console.log(templates);
* });
*
* @param {Object} params Factor parameters.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(GuardianManager, 'getFactorTemplates', 'factorsTemplates.get');

/**
* Update Guardian enrollment and verification factor templates
*
* @method updateFactorTemplates
* @memberOf module:management.GuardianManager.prototype
*
* management.guardian.updateFactorProvider({ name: 'sms' }, {
* enrollment_message: "{{code}} is your verification code for {{tenant.friendly_name}}. Please enter this code to verify your enrollment.",
* verification_message: "{{code}} is your verification code for {{tenant.friendly_name}}"
* }, function(err, templates) {
* console.log(templates);
* });
*
* @param {Object} params Factor parameters.
* @param {Object} data Updated factor templates data.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(GuardianManager, 'updateFactorTemplates', 'factorsTemplates.update');

/**
* Update Guardian Factor
*
* @method updateFactor
* @memberOf module:management.GuardianManager.prototype
*
* management.guardian.updateFactor({ name: 'sms' }, {
* enabled: true
* }, function(err, factor) {
* console.log(factor);
* });
*
* @param {Object} params Factor parameters.
* @param {Object} data Updated factor data.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(GuardianManager, 'updateFactor', 'factors.update');

module.exports = GuardianManager;
Loading

0 comments on commit 0593007

Please sign in to comment.