mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-25 16:42:34 +00:00
Removed tmp js examples
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script src="keycloak.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script>
|
||||
keycloak.init({
|
||||
clientId : 'test-app',
|
||||
clientSecret : 'password',
|
||||
baseUrl : 'http://localhost:8081/auth-server',
|
||||
realm : 'test',
|
||||
redirectUri : 'http://localhost/js'
|
||||
});
|
||||
|
||||
if (keycloak.authenticated) {
|
||||
document.write('User: ' + keycloak.user);
|
||||
} else {
|
||||
document.write('<a href="#" id="login" onclick="keycloak.login(location.hash)">Login</a>');
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,126 +0,0 @@
|
||||
window.keycloak = (function () {
|
||||
var kc = {};
|
||||
var config = {
|
||||
baseUrl: null,
|
||||
clientId: null,
|
||||
clientSecret: null,
|
||||
realm: null,
|
||||
redirectUri: null
|
||||
};
|
||||
|
||||
kc.init = function (c) {
|
||||
for (var prop in config) {
|
||||
if (c[prop]) {
|
||||
config[prop] = c[prop];
|
||||
}
|
||||
|
||||
if (!config[prop]) {
|
||||
throw new Error(prop + 'not defined');
|
||||
}
|
||||
}
|
||||
|
||||
if (!processCallback()) {
|
||||
window.location.href = getLoginUrl() + '&prompt=none';
|
||||
}
|
||||
}
|
||||
|
||||
kc.login = function () {
|
||||
window.location.href = getLoginUrl();
|
||||
}
|
||||
|
||||
return kc;
|
||||
|
||||
function getLoginUrl(fragment) {
|
||||
var state = createUUID();
|
||||
if (fragment) {
|
||||
state += '#' + fragment;
|
||||
}
|
||||
sessionStorage.state = state;
|
||||
var url = config.baseUrl + '/rest/realms/' + encodeURIComponent(config.realm) + '/tokens/login?response_type=code&client_id='
|
||||
+ encodeURIComponent(config.clientId) + '&redirect_uri=' + encodeURIComponent(config.redirectUri) + '&state=' + encodeURIComponent(state);
|
||||
return url;
|
||||
}
|
||||
|
||||
function parseToken(token) {
|
||||
return JSON.parse(atob(token.split('.')[1]));
|
||||
}
|
||||
|
||||
function processCallback() {
|
||||
var code = getQueryParam('code');
|
||||
var error = getQueryParam('error');
|
||||
var state = getQueryParam('state');
|
||||
|
||||
if (!(code || error)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (state != sessionStorage.state) {
|
||||
console.error('Invalid state');
|
||||
return true;
|
||||
}
|
||||
|
||||
if (code) {
|
||||
console.info('Received code');
|
||||
|
||||
var clientId = encodeURIComponent(config.clientId);
|
||||
var clientSecret = encodeURIComponent(config.clientSecret);
|
||||
var realm = encodeURIComponent(config.realm);
|
||||
|
||||
var params = 'code=' + code + '&client_id=' + clientId + '&password=' + clientSecret;
|
||||
var url = config.baseUrl + '/rest/realms/' + realm + '/tokens/access/codes'
|
||||
|
||||
var http = new XMLHttpRequest();
|
||||
http.open('POST', url, false);
|
||||
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
|
||||
http.send(params);
|
||||
if (http.status == 200) {
|
||||
kc.token = JSON.parse(http.responseText)['access_token'];
|
||||
kc.tokenParsed = parseToken(kc.token);
|
||||
kc.authenticated = true;
|
||||
kc.user = kc.tokenParsed.prn;
|
||||
|
||||
console.info('Authenticated');
|
||||
}
|
||||
|
||||
updateLocation(state);
|
||||
return true;
|
||||
} else if (error) {
|
||||
console.info('Error ' + error);
|
||||
updateLocation(state);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function updateLocation(state) {
|
||||
var fragment = '';
|
||||
if (state && state.indexOf('#') != -1) {
|
||||
fragment = state.substr(state.indexOf('#'));
|
||||
}
|
||||
|
||||
window.history.replaceState({}, document.title, location.protocol + "//" + location.host + location.pathname + fragment);
|
||||
}
|
||||
|
||||
function getQueryParam(name) {
|
||||
var params = window.location.search.substring(1).split('&');
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
var p = params[i].split('=');
|
||||
if (decodeURIComponent(p[0]) == name) {
|
||||
return p[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createUUID() {
|
||||
var s = [];
|
||||
var hexDigits = '0123456789abcdef';
|
||||
for (var i = 0; i < 36; i++) {
|
||||
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
|
||||
}
|
||||
s[14] = '4';
|
||||
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
|
||||
s[8] = s[13] = s[18] = s[23] = '-';
|
||||
var uuid = s.join('');
|
||||
return uuid;
|
||||
}
|
||||
})();
|
||||
@@ -1,60 +0,0 @@
|
||||
{
|
||||
"id": "test",
|
||||
"realm": "test",
|
||||
"enabled": true,
|
||||
"tokenLifespan": 300,
|
||||
"accessCodeLifespan": 10,
|
||||
"accessCodeLifespanUserAction": 600,
|
||||
"sslNotRequired": true,
|
||||
"cookieLoginAllowed": true,
|
||||
"registrationAllowed": true,
|
||||
"accountManagement": true,
|
||||
"resetPasswordAllowed": true,
|
||||
"privateKey": "MIICXAIBAAKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQABAoGAfmO8gVhyBxdqlxmIuglbz8bcjQbhXJLR2EoS8ngTXmN1bo2L90M0mUKSdc7qF10LgETBzqL8jYlQIbt+e6TH8fcEpKCjUlyq0Mf/vVbfZSNaVycY13nTzo27iPyWQHK5NLuJzn1xvxxrUeXI6A2WFpGEBLbHjwpx5WQG9A+2scECQQDvdn9NE75HPTVPxBqsEd2z10TKkl9CZxu10Qby3iQQmWLEJ9LNmy3acvKrE3gMiYNWb6xHPKiIqOR1as7L24aTAkEAtyvQOlCvr5kAjVqrEKXalj0Tzewjweuxc0pskvArTI2Oo070h65GpoIKLc9jf+UA69cRtquwP93aZKtW06U8dQJAF2Y44ks/mK5+eyDqik3koCI08qaC8HYq2wVl7G2QkJ6sbAaILtcvD92ToOvyGyeE0flvmDZxMYlvaZnaQ0lcSQJBAKZU6umJi3/xeEbkJqMfeLclD27XGEFoPeNrmdx0q10Azp4NfJAY+Z8KRyQCR2BEG+oNitBOZ+YXF9KCpH3cdmECQHEigJhYg+ykOvr1aiZUMFT72HU0jnmQe2FVekuG+LJUt2Tm7GtMjTFoGpf0JwrVuZN39fOYAlo+nTixgeW7X8Y=",
|
||||
"publicKey": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB",
|
||||
"requiredCredentials": [ "password" ],
|
||||
"requiredApplicationCredentials": [ "password" ],
|
||||
"requiredOAuthClientCredentials": [ "password" ],
|
||||
"defaultRoles": [ "user" ],
|
||||
"users" : [
|
||||
{
|
||||
"username" : "test-user@localhost",
|
||||
"enabled": true,
|
||||
"email" : "test-user@localhost",
|
||||
"credentials" : [
|
||||
{ "type" : "password",
|
||||
"value" : "password" }
|
||||
]
|
||||
}
|
||||
],
|
||||
"roles": [
|
||||
{
|
||||
"name": "user",
|
||||
"description": "Have User privileges"
|
||||
},
|
||||
{
|
||||
"name": "admin",
|
||||
"description": "Have Administrator privileges"
|
||||
}
|
||||
],
|
||||
"roleMappings": [
|
||||
{
|
||||
"username": "test-user@localhost",
|
||||
"roles": ["user"]
|
||||
}
|
||||
],
|
||||
"applications": [
|
||||
{
|
||||
"name": "test-app",
|
||||
"enabled": true,
|
||||
"adminUrl": "http://localhost:8081/app/logout",
|
||||
"webOrigins": [ "http://localhost", "http://localhost:8000", "http://localhost:8080" ],
|
||||
"credentials": [
|
||||
{
|
||||
"type": "password",
|
||||
"value": "password"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user