Repository: auth0/auth0.js
Pull request #336 (2017-01-30 13:17:17)

popup.authorize should not require redirectURI when using OWP

codecov-io: # [Codecov](https://codecov.io/gh/auth0/auth0.js/pull/336?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request head (`fix-redirecturi-popup@7c34a7c`).

------

[Continue to review full report at Codecov](https://codecov.io/gh/auth0/auth0.js/pull/336?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/auth0/auth0.js/pull/336?src=pr&el=footer). Last update [e33f87b...7c34a7c](https://codecov.io/gh/auth0/auth0.js/compare/e33f87b246897075a7cde4e20bc846b52b738ede...7c34a7c3620fd419bfceec910b4a14b84eb824e1?src=pr&el=footer&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
codecov-io: # [Codecov](https://codecov.io/gh/auth0/auth0.js/pull/336?src=pr&el=h1) Report
> Merging [#336](https://codecov.io/gh/auth0/auth0.js/pull/336?src=pr&el=desc) into [master](https://codecov.io/gh/auth0/auth0.js/commit/e33f87b246897075a7cde4e20bc846b52b738ede?src=pr&el=desc) will **increase** coverage by `<.01%`.


```diff
@@            Coverage Diff             @@
##           master     #336      +/-   ##
==========================================
+ Coverage   98.82%   98.82%   +<.01%     
==========================================
  Files          30       30              
  Lines        1023     1024       +1     
  Branches      167      168       +1     
==========================================
+ Hits         1011     1012       +1     
  Misses         12       12
```


| [Impacted Files](https://codecov.io/gh/auth0/auth0.js/pull/336?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/web-auth/popup.js](https://codecov.io/gh/auth0/auth0.js/compare/e33f87b246897075a7cde4e20bc846b52b738ede...7c34a7c3620fd419bfceec910b4a14b84eb824e1?src=pr&el=tree#diff-c3JjL3dlYi1hdXRoL3BvcHVwLmpz) | `100% <100%> (ø)` | :white_check_mark: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/auth0/auth0.js/pull/336?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/auth0/auth0.js/pull/336?src=pr&el=footer). Last update [e33f87b...7edb3f9](https://codecov.io/gh/auth0/auth0.js/compare/e33f87b246897075a7cde4e20bc846b52b738ede...7edb3f97cf0e51960b8a4733970dd500648f09a6?src=pr&el=footer&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Patch:
diff --git a/example/index.html b/example/index.html
index 8d89e82..badb42e 100644
--- a/example/index.html
+++ b/example/index.html
@@ -261,7 +261,7 @@
       e.preventDefault();
 
       webAuth.popup.loginWithCredentials({
-        connection: 'tests',
+        connection: 'acme',
         username: $('.popup-login-username').val(),
         password: $('.popup-login-password').val(),
         scope: 'openid',
diff --git a/src/authentication/index.js b/src/authentication/index.js
index 95361b7..8a35dc4 100644
--- a/src/authentication/index.js
+++ b/src/authentication/index.js
@@ -81,7 +81,7 @@ Authentication.prototype.buildAuthorizeUrl = function (options) {
   /* eslint-disable */
   assert.check(params, { type: 'object', message: 'options parameter is not valid' }, {
     clientID: { type: 'string', message: 'clientID option is required' },
-    redirectUri: { type: 'string', message: 'redirectUri option is required' },
+    redirectUri: { optional: true, type: 'string', message: 'redirectUri option is required' },
     responseType: { type: 'string', message: 'responseType option is required' },
     nonce: { type: 'string', message: 'nonce option is required', condition: function(o) {
       return o.responseType.indexOf('code') === -1 && o.responseType.indexOf('id_token') !== -1;
diff --git a/src/web-auth/popup.js b/src/web-auth/popup.js
index 94ee1ff..f87ba78 100644
--- a/src/web-auth/popup.js
+++ b/src/web-auth/popup.js
@@ -64,9 +64,12 @@ Popup.prototype.authorize = function (options, cb) {
     responseType: { type: 'string', message: 'responseType option is required' }
   });
 
+  relayUrl = urljoin(this.baseOptions.rootUrl, 'relay.html');
+
   // used by server to render the relay page instead of sending the chunk in the
   // url to the callback
   params.owp = true;
+  params.redirectUri = undefined;
 
   params = this.transactionManager.process(params);
 
@@ -74,8 +77,6 @@ Popup.prototype.authorize = function (options, cb) {
 
   popup = this.getPopupHandler(options);
 
-  relayUrl = urljoin(this.baseOptions.rootUrl, 'relay.html');
-
   return popup.load(url, relayUrl, {}, responseHandler(cb));
 };
 


Test patch:
diff --git a/test/web-auth/popup.test.js b/test/web-auth/popup.test.js
index 6b1a7bc..57c016f 100644
--- a/test/web-auth/popup.test.js
+++ b/test/web-auth/popup.test.js
@@ -85,7 +85,7 @@ describe('auth0.WebAuth.popup', function () {
 
     it('should open the authorize page in a popup', function (done) {
       stub(PopupHandler.prototype, 'load', function(url, relayUrl, options, cb) {
-        expect(url).to.be('https://me.auth0.com/authorize?client_id=...&response_type=id_token&redirect_uri=http%3A%2F%2Fpage.com%2Fcallback&connection=the_connection&nonce=123&state=456&owp=true');
+        expect(url).to.be('https://me.auth0.com/authorize?client_id=...&response_type=id_token&connection=the_connection&nonce=123&state=456&owp=true');
         expect(relayUrl).to.be('https://me.auth0.com/relay.html');
         expect(options).to.eql({});
         cb(null, {