Last active
May 19, 2017 15:21
-
-
Save kraihn/a96cd8acd9265ca10dace2ce48cf8986 to your computer and use it in GitHub Desktop.
Intercept redirect_uri and set id_token from Auth0 as bearer token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setToken(t) { | |
var token = "Bearer " + t; | |
swaggerUi.api.clientAuthorizations.remove('bearer_key'); | |
swaggerUi.api.clientAuthorizations.add("bearer", new SwaggerClient.ApiKeyAuthorization("Authorization", token, "header")); | |
} | |
if (!window.isOpenReplaced) { | |
window.open = function (open) { | |
return function (url) { | |
// send us back to where we came from! | |
url = url.replace('redirect_uri=' + encodeURIComponent(window.location.origin + window.location.pathname) + 'o2c.html', 'redirect_uri=' + encodeURIComponent(window.location.origin + window.location.pathname)); | |
return open.call(window, url); | |
}; | |
}(window.open); | |
window.isOpenReplaced = true; | |
} | |
if (window.location.hash) { | |
var queryParams = window.location.hash.substring(1).split('&'); | |
for (var i = 0; i < queryParams.length; i++) { | |
if (queryParams[i].startsWith("id_token")) { | |
var idToken = queryParams[i].split('=')[1]; | |
localStorage.setItem('id_token', idToken); | |
break; | |
} | |
} | |
} | |
if (localStorage.getItem('id_token')) { | |
setToken(localStorage.getItem('id_token')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment