diff --git a/src/helper/response-handler.js b/src/helper/response-handler.js index 929aacb2..c136a5ec 100644 --- a/src/helper/response-handler.js +++ b/src/helper/response-handler.js @@ -37,6 +37,10 @@ function wrapCallback(cb) { errObj.name = err.name; } + if (err.policy) { + errObj.policy = err.policy; + } + return cb(errObj); } diff --git a/src/web-auth/index.js b/src/web-auth/index.js index afab6320..1df2c130 100644 --- a/src/web-auth/index.js +++ b/src/web-auth/index.js @@ -259,6 +259,10 @@ WebAuth.prototype.login = function (options) { 'audience' ]).with(options); + assert.check(params, { type: 'object', message: 'options parameter is not valid' }, { + responseType: { type: 'string', message: 'responseType option is required' } + }); + params = this.transactionManager.process(params); windowHelper.redirect(this.client.buildAuthorizeUrl(params)); diff --git a/src/web-auth/redirect.js b/src/web-auth/redirect.js index 3e7e1eea..376b4b39 100644 --- a/src/web-auth/redirect.js +++ b/src/web-auth/redirect.js @@ -2,6 +2,7 @@ var UsernamePassword = require('./username-password'); var TransactionManager = require('./transaction-manager'); var objectHelper = require('../helper/object'); var Warn = require('../helper/warn'); +var assert = require('../helper/assert'); function Redirect(client, options) { this.baseOptions = options; @@ -36,6 +37,10 @@ Redirect.prototype.login = function (options, cb) { this.warn.warning('`webauth.redirect.login` will be soon deprecated, use `webauth.login` instead.'); + assert.check(params, { type: 'object', message: 'options parameter is not valid' }, { + responseType: { type: 'string', message: 'responseType option is required' } + }); + params = this.transactionManager.process(params); usernamePassword = new UsernamePassword(this.baseOptions); diff --git a/test/helper/response-handler.test.js b/test/helper/response-handler.test.js index 6e9f1a5c..575b7217 100644 --- a/test/helper/response-handler.test.js +++ b/test/helper/response-handler.test.js @@ -23,6 +23,7 @@ describe('helpers responseHandler', function () { assert_err.response.statusText = 'Bad request'; assert_err.response.body = { error: 'the_error_code', + policy: 'the policy', error_description: 'The error description.', name: 'SomeName' }; @@ -34,6 +35,7 @@ describe('helpers responseHandler', function () { statusCode: 400, statusText: 'Bad request', code: 'the_error_code', + policy: 'the policy', description: 'The error description.', name: 'SomeName' }); diff --git a/test/web-auth/redirect.test.js b/test/web-auth/redirect.test.js index 1d5f483a..20865f43 100644 --- a/test/web-auth/redirect.test.js +++ b/test/web-auth/redirect.test.js @@ -553,13 +553,21 @@ describe('auth0.WebAuth.redirect', function () { domain: 'me.auth0.com', clientID: '...', redirectUri: 'http://page.com/callback', - responseType: 'code', _sendTelemetry: false }); }); + it('should check that responseType is present', function() { + var _this = this; + expect(function() { + _this.auth0.login({ connection: 'facebook' }) + }).to.throwException(function (e) { + expect(e.message).to.be('responseType option is required'); + }); + }) + it('should redirect to authorize', function () { - this.auth0.login({connection: 'facebook', state: '1234'}) + this.auth0.login({responseType: 'code', connection: 'facebook', state: '1234'}) expect(global.window.location).to.be('https://me.auth0.com/authorize?connection=facebook&client_id=...&response_type=code&redirect_uri=http%3A%2F%2Fpage.com%2Fcallback&state=1234'); }); diff --git a/test/web-auth/web-auth.test.js b/test/web-auth/web-auth.test.js index e9e1a238..95dc19db 100644 --- a/test/web-auth/web-auth.test.js +++ b/test/web-auth/web-auth.test.js @@ -254,6 +254,28 @@ describe('auth0.WebAuth', function () { }); }); + context('login', function () { + it('should check that responseType is present', function () { + global.window = { location: '' }; + var webAuth = new WebAuth({ + domain: 'me.auth0.com', + redirectUri: 'http://page.com/callback', + clientID: '...', + scope: 'openid name read:blog', + audience: 'urn:site:demo:blog', + _sendTelemetry: false + }); + + expect(function() { + webAuth.login({ connection: 'facebook' }) + }).to.throwException(function (e) { + expect(e.message).to.be('responseType option is required'); + }); + + delete global.window; + }); + }); + context('renewAuth', function () { beforeEach(function(){ global.window = {};