Created
June 22, 2021 12:50
-
-
Save r00ta/61340a7863be1193cafa86ce253425a9 to your computer and use it in GitHub Desktop.
index.html
This file contains hidden or 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
<html> | |
<head> | |
<title>keycloak-spa</title> | |
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> | |
<script src="https://keycloak-route-baaas-cp-demo.apps.kogito-cloud.automation.rhmw.io/auth/js/keycloak.js"></script> | |
<script> | |
var keycloak = new Keycloak({ | |
url: 'https://keycloak-route-baaas-cp-demo.apps.kogito-cloud.automation.rhmw.io/auth', | |
realm: 'baaas', | |
clientId: 'baaas-mcp' | |
}); | |
keycloak.init({onLoad: 'login-required'}).success(function () { | |
keycloak.loadUserProfile() | |
.then(function(profile) { | |
alert(JSON.stringify(profile, null, " ")) | |
}).catch(function() { | |
alert('Failed to load user profile'); | |
}); | |
console.log('User is now authenticated.'); | |
}).error(function () { | |
window.location.reload(); | |
}); | |
function makeAjaxRequest() { | |
axios.get("/decisions", { | |
headers: { | |
'Authorization': 'Bearer ' + keycloak.token | |
} | |
}) | |
.then( function (response) { | |
console.log("Response: ", response.status); | |
}).catch(function (error) { | |
console.log('refreshing'); | |
keycloak.updateToken(5).then(function () { | |
console.log('Token refreshed'); | |
}).catch(function () { | |
console.log('Failed to refresh token'); | |
window.location.reload(); | |
}); | |
}); | |
} | |
</script> | |
</head> | |
<body> | |
<button onclick="makeAjaxRequest()">Request</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment