Skip to content

Commit

Permalink
Add ability to override redirectUrl in swagger-oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsen1 committed Mar 24, 2015
1 parent b78a8e5 commit ede1faa
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ onComplete | This is a callback function parameter which can be passed to be not
onFailure | This is a callback function parameter which can be passed to be notified of when SwaggerUI encountered a failure was unable to render.
highlightSizeThreshold | Any size response below this threshold will be highlighted syntactically, attempting to highlight large responses can lead to browser hangs, not including a threshold will default to highlight all returned responses.
supportedSubmitMethods | An array of of the HTTP operations that will have the 'Try it out!` option. An empty array disables all operations. This does not filter the operations from the display.
redirectUrl | OAuth redirect URL

* All other parameters are explained in greater detail below

Expand Down
3 changes: 2 additions & 1 deletion dist/lib/swagger-oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ function handleLogin() {
var authSchemes = window.swaggerUi.api.authSchemes;
var host = window.location;
var pathname = location.pathname.substring(0, location.pathname.lastIndexOf("/"));
var redirectUrl = host.protocol + '//' + host.host + pathname + '/o2c.html';
var defaultRedirectUrl = host.protocol + '//' + host.host + pathname + '/o2c.html';
var redirectUrl = window.oAuthRedirectUrl || defaultRedirectUrl;
var url = null;

for (var key in authSchemes) {
Expand Down
4 changes: 4 additions & 0 deletions dist/swagger-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ window.SwaggerUi = Backbone.Router.extend({
];
}

if (typeof options.redirectUrl === 'string') {
window.oAuthRedirectUrl = options.redirectUrl;
}

// Create an empty div which contains the dom_id
if (! $('#' + this.dom_id).length){
$('body').append('<div id="' + this.dom_id + '"></div>') ;
Expand Down
4 changes: 2 additions & 2 deletions dist/swagger-ui.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion lib/swagger-oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ function handleLogin() {
var authSchemes = window.swaggerUi.api.authSchemes;
var host = window.location;
var pathname = location.pathname.substring(0, location.pathname.lastIndexOf("/"));
var redirectUrl = host.protocol + '//' + host.host + pathname + '/o2c.html';
var defaultRedirectUrl = host.protocol + '//' + host.host + pathname + '/o2c.html';
var redirectUrl = window.oAuthRedirectUrl || defaultRedirectUrl;
var url = null;

for (var key in authSchemes) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/javascript/SwaggerUi.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ window.SwaggerUi = Backbone.Router.extend({
];
}

if (typeof options.redirectUrl === 'string') {
window.oAuthRedirectUrl = options.redirectUrl;
}

// Create an empty div which contains the dom_id
if (! $('#' + this.dom_id).length){
$('body').append('<div id="' + this.dom_id + '"></div>') ;
Expand Down

0 comments on commit ede1faa

Please sign in to comment.