Skip to content

Commit 0af0725

Browse files
committed
Remove redirectUri option and test cordovaRedirectUri
1 parent aef1877 commit 0af0725

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/remotestorage.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,8 @@ RemoteStorage.prototype = {
175175
* Initiate the OAuth authorization flow.
176176
*
177177
* @param {object} options
178-
* @param {string} [options.authURL] - URL to the authorization endpoint
178+
* @param {string} [options.authURL] - URL of the authorization endpoint
179179
* @param {string} [options.scope] - access scope
180-
* @param {string} [options.redirectUri] - client URL that should be redirected
181-
* to after authorization
182180
* @param {string} [options.clientId] - client identifier (defaults to the
183181
* origin of the redirectUri)
184182
*/
@@ -188,9 +186,7 @@ RemoteStorage.prototype = {
188186
options.scope = this.access.scopeParameter;
189187
}
190188

191-
if (typeof options.redirectUri === 'undefined') {
192-
options.redirectUri = globalContext.cordova ? config.cordovaRedirectUri : String(Authorize.getLocation());
193-
}
189+
options.redirectUri = globalContext.cordova ? config.cordovaRedirectUri : String(Authorize.getLocation());
194190

195191
if (typeof options.clientId === 'undefined') {
196192
options.clientId = options.redirectUri.match(/^(https?:\/\/[^/]+)/)[0];

test/unit/authorize-suite.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ define([ 'require', './src/authorize', './src/config'], function(require, Author
9797

9898
Authorize.openWindow = function(url, uri) {
9999
test.assertAnd(uri, redirectUri);
100+
delete global.cordova;
100101
test.done();
101102
};
102103

test/unit/remotestorage-suite.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ define(['require', 'tv4', './src/eventhandling'], function (require, tv4, eventH
655655
},
656656

657657
{
658-
desc: "#authorize uses the given redirectUri",
658+
desc: "#authorize uses the cordovaRedirectUri when in Cordova",
659659
run: function (env, test) {
660660
global.document = {
661661
location: {
@@ -664,14 +664,21 @@ define(['require', 'tv4', './src/eventhandling'], function (require, tv4, eventH
664664
}
665665
};
666666

667-
const authURL = 'https://provider.com/oauth';
668-
env.rs.access.claim('contacts', 'r');
667+
global.cordova = { foo: 'bar' }; // Pretend we run in Cordova
669668

670-
env.rs.authorize({ authURL, redirectUri: 'http://my.custom-redirect.url' });
669+
global.Authorize.openWindow = function(url, redirectUri) {
670+
test.assertAnd(url, 'https://provider.com/oauth?redirect_uri=https%3A%2F%2Fmy.custom-redirect.url&scope=contacts%3Ar&client_id=https%3A%2F%2Fmy.custom-redirect.url&response_type=token');
671+
test.assertAnd(redirectUri, 'https://my.custom-redirect.url');
672+
delete global.cordova;
673+
delete global.document;
674+
test.done();
675+
};
671676

672-
test.assert(document.location.href, 'https://provider.com/oauth?redirect_uri=http%3A%2F%2Fmy.custom-redirect.url&scope=contacts%3Ar&client_id=http%3A%2F%2Fmy.custom-redirect.url&response_type=token');
677+
const authURL = 'https://provider.com/oauth';
673678

674-
delete global.document;
679+
env.rs.access.claim('contacts', 'r');
680+
env.rs.setCordovaRedirectUri('https://my.custom-redirect.url');
681+
env.rs.authorize({ authURL });
675682
}
676683
},
677684

0 commit comments

Comments
 (0)