Skip to content

Commit 36b9955

Browse files
authored
Merge pull request auth0#375 from auth0/fix/add-option-to-bypass-validation
Add flag to bypass id_token validation
2 parents d4dc323 + 1774e85 commit 36b9955

File tree

4 files changed

+37
-18
lines changed

4 files changed

+37
-18
lines changed

src/auth/OAUthWithIDTokenValidation.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ var HS256_IGNORE_VALIDATION_MESSAGE =
1313
* @constructor
1414
* @memberOf module:auth
1515
*
16-
* @param {Object} oauth An instance of @type {OAuthAuthenticator}
17-
* @param {Object} options Authenticator options.
18-
* @param {String} options.domain AuthenticationClient server domain
19-
* @param {String} [options.clientId] Default client ID.
20-
* @param {String} [options.clientSecret] Default client Secret.
21-
* @param {String} [options.supportedAlgorithms] Algorithms that your application expects to receive
16+
* @param {Object} oauth An instance of @type {OAuthAuthenticator}
17+
* @param {Object} options Authenticator options.
18+
* @param {String} options.domain AuthenticationClient server domain
19+
* @param {String} [options.clientId] Default client ID.
20+
* @param {String} [options.clientSecret] Default client Secret.
21+
* @param {String} [options.supportedAlgorithms] Algorithms that your application expects to receive
22+
* @param {Boolean} [options.__bypassIdTokenValidation] Whether the id_token should be validated or not
2223
*/
2324
var OAUthWithIDTokenValidation = function(oauth, options) {
2425
if (!oauth) {
@@ -34,6 +35,7 @@ var OAUthWithIDTokenValidation = function(oauth, options) {
3435
}
3536

3637
this.oauth = oauth;
38+
this.__bypassIdTokenValidation = options.__bypassIdTokenValidation;
3739
this.clientId = options.clientId;
3840
this.clientSecret = options.clientSecret;
3941
this.domain = options.domain;
@@ -56,8 +58,11 @@ var OAUthWithIDTokenValidation = function(oauth, options) {
5658
* @return {Promise|undefined}
5759
*/
5860
OAUthWithIDTokenValidation.prototype.create = function(params, data, cb) {
61+
const _this = this;
5962
const createAndValidate = this.oauth.create(params, data).then(r => {
60-
var _this = this;
63+
if (_this.__bypassIdTokenValidation) {
64+
return r;
65+
}
6166
if (r.id_token) {
6267
function getKey(header, callback) {
6368
if (header.alg === 'HS256') {

src/auth/OAuthAuthenticator.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ var OAUthWithIDTokenValidation = require('./OAUthWithIDTokenValidation');
1212
* @constructor
1313
* @memberOf module:auth
1414
*
15-
* @param {Object} options Authenticator options.
16-
* @param {String} options.baseUrl The Auth0 account URL.
17-
* @param {String} options.domain AuthenticationClient server domain
18-
* @param {String} [options.clientId] Default client ID.
19-
* @param {String} [options.clientSecret] Default client Secret.
15+
* @param {Object} options Authenticator options.
16+
* @param {String} options.baseUrl The Auth0 account URL.
17+
* @param {String} options.domain AuthenticationClient server domain
18+
* @param {String} [options.clientId] Default client ID.
19+
* @param {String} [options.clientSecret] Default client Secret.
20+
* @param {Boolean} [options.__bypassIdTokenValidation] Whether the id_token should be validated or not
2021
*/
2122
var OAuthAuthenticator = function(options) {
2223
if (!options) {

src/auth/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ var BASE_URL_FORMAT = 'https://%s';
3737
* clientId: '{OPTIONAL_CLIENT_ID}'
3838
* });
3939
*
40-
* @param {Object} options Options for the Authentication Client SDK.
41-
* @param {String} options.domain AuthenticationClient server domain.
42-
* @param {String} [options.clientId] Default client ID.
43-
* @param {String} [options.clientSecret] Default client Secret.
44-
* @param {String} [options.supportedAlgorithms] Algorithms that your application expects to receive
40+
* @param {Object} options Options for the Authentication Client SDK.
41+
* @param {String} options.domain AuthenticationClient server domain.
42+
* @param {String} [options.clientId] Default client ID.
43+
* @param {String} [options.clientSecret] Default client Secret.
44+
* @param {String} [options.supportedAlgorithms] Algorithms that your application expects to receive
45+
* @param {Boolean} [options.__bypassIdTokenValidation] Whether the id_token should be validated or not
4546
*/
4647
var AuthenticationClient = function(options) {
4748
if (!options || typeof options !== 'object') {
@@ -61,7 +62,8 @@ var AuthenticationClient = function(options) {
6162
'Content-Type': 'application/json'
6263
},
6364
baseUrl: util.format(BASE_URL_FORMAT, options.domain),
64-
supportedAlgorithms: options.supportedAlgorithms
65+
supportedAlgorithms: options.supportedAlgorithms,
66+
__bypassIdTokenValidation: options.__bypassIdTokenValidation
6567
};
6668

6769
if (options.telemetry !== false) {

test/auth/oauth-with-idtoken-validation.tests.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ describe('OAUthWithIDTokenValidation', function() {
7777
var oauthWithValidation = new OAUthWithIDTokenValidation(oauth, {});
7878
oauthWithValidation.create(PARAMS, DATA, done);
7979
});
80+
it('Bypasses validation when options.__bypassIdTokenValidation is true', function(done) {
81+
var oauth = {
82+
create: function() {
83+
return new Promise(res => res({ id_token: 'foobar' }));
84+
}
85+
};
86+
var oauthWithValidation = new OAUthWithIDTokenValidation(oauth, {
87+
__bypassIdTokenValidation: true
88+
});
89+
oauthWithValidation.create(PARAMS, DATA, done);
90+
});
8091
it('Calls jwt.verify with token and algs', function(done) {
8192
var oauth = {
8293
create: function() {

0 commit comments

Comments
 (0)