commit
89c89b4867
3 changed files with 53 additions and 16 deletions
|
@ -48,6 +48,7 @@
|
||||||
<button onclick="refreshTimeSkew()">refresh timeSkew</button>
|
<button onclick="refreshTimeSkew()">refresh timeSkew</button>
|
||||||
<button onclick="sendBearerToKeycloak()">Bearer to keycloak</button>
|
<button onclick="sendBearerToKeycloak()">Bearer to keycloak</button>
|
||||||
<button onclick="createUser()">Create user</button>
|
<button onclick="createUser()">Create user</button>
|
||||||
|
<button onclick="reentrancyCallback()">Reentrancy callback</button>
|
||||||
|
|
||||||
|
|
||||||
<select id="flowSelect">
|
<select id="flowSelect">
|
||||||
|
@ -72,34 +73,35 @@
|
||||||
<pre style="background-color: #ddd; border: 1px solid #ccc; padding: 10px;" id="events"></pre>
|
<pre style="background-color: #ddd; border: 1px solid #ccc; padding: 10px;" id="events"></pre>
|
||||||
|
|
||||||
<h2>Info</h2>
|
<h2>Info</h2>
|
||||||
TimeSkew: <div id="timeSkew"></div>
|
TimeSkew:
|
||||||
|
<div id="timeSkew"></div>
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function loadProfile() {
|
function loadProfile() {
|
||||||
keycloak.loadUserProfile().success(function(profile) {
|
keycloak.loadUserProfile().success(function (profile) {
|
||||||
output(profile);
|
output(profile);
|
||||||
}).error(function() {
|
}).error(function () {
|
||||||
output('Failed to load profile');
|
output('Failed to load profile');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadUserInfo() {
|
function loadUserInfo() {
|
||||||
keycloak.loadUserInfo().success(function(userInfo) {
|
keycloak.loadUserInfo().success(function (userInfo) {
|
||||||
output(userInfo);
|
output(userInfo);
|
||||||
}).error(function() {
|
}).error(function () {
|
||||||
output('Failed to load user info');
|
output('Failed to load user info');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshToken(minValidity) {
|
function refreshToken(minValidity) {
|
||||||
keycloak.updateToken(minValidity).success(function(refreshed) {
|
keycloak.updateToken(minValidity).success(function (refreshed) {
|
||||||
if (refreshed) {
|
if (refreshed) {
|
||||||
output(keycloak.tokenParsed);
|
output(keycloak.tokenParsed);
|
||||||
} else {
|
} else {
|
||||||
output('Token not refreshed, valid for ' + Math.round(keycloak.tokenParsed.exp + keycloak.timeSkew - new Date().getTime() / 1000) + ' seconds');
|
output('Token not refreshed, valid for ' + Math.round(keycloak.tokenParsed.exp + keycloak.timeSkew - new Date().getTime() / 1000) + ' seconds');
|
||||||
}
|
}
|
||||||
}).error(function() {
|
}).error(function () {
|
||||||
output('Failed to refresh token');
|
output('Failed to refresh token');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -129,7 +131,7 @@ TimeSkew: <div id="timeSkew"></div>
|
||||||
if (!url) url = window.location.href;
|
if (!url) url = window.location.href;
|
||||||
name = name.replace(/[\[\]]/g, "\\$&");
|
name = name.replace(/[\[\]]/g, "\\$&");
|
||||||
var regex = new RegExp("[?&#]" + name + "(=([^&#]*)|&|#|$)"),
|
var regex = new RegExp("[?&#]" + name + "(=([^&#]*)|&|#|$)"),
|
||||||
results = regex.exec(url);
|
results = regex.exec(url);
|
||||||
if (!results) return null;
|
if (!results) return null;
|
||||||
if (!results[2]) return '';
|
if (!results[2]) return '';
|
||||||
return decodeURIComponent(results[2].replace(/\+/g, " "));
|
return decodeURIComponent(results[2].replace(/\+/g, " "));
|
||||||
|
@ -161,12 +163,12 @@ TimeSkew: <div id="timeSkew"></div>
|
||||||
|
|
||||||
var url = 'http://localhost:8280/js-database/customers';
|
var url = 'http://localhost:8280/js-database/customers';
|
||||||
if (window.location.href.indexOf("8643") > -1) {
|
if (window.location.href.indexOf("8643") > -1) {
|
||||||
url = url.replace("8280","8643");
|
url = url.replace("8280", "8643");
|
||||||
url = url.replace("http","https");
|
url = url.replace("http", "https");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.location.href.indexOf("8180") > -1) {
|
if (window.location.href.indexOf("8180") > -1) {
|
||||||
url = url.replace("8280","8180");
|
url = url.replace("8280", "8180");
|
||||||
}
|
}
|
||||||
|
|
||||||
var req = new XMLHttpRequest();
|
var req = new XMLHttpRequest();
|
||||||
|
@ -194,6 +196,9 @@ TimeSkew: <div id="timeSkew"></div>
|
||||||
if (window.location.href.indexOf("8643") > -1) {
|
if (window.location.href.indexOf("8643") > -1) {
|
||||||
url = url.replace("8180","8543");
|
url = url.replace("8180","8543");
|
||||||
url = url.replace("http","https");
|
url = url.replace("http","https");
|
||||||
|
if (window.location.href.indexOf("8543") > -1) {
|
||||||
|
url = url.replace("8180", "8543");
|
||||||
|
url = url.replace("http", "https");
|
||||||
}
|
}
|
||||||
|
|
||||||
var req = new XMLHttpRequest();
|
var req = new XMLHttpRequest();
|
||||||
|
@ -219,8 +224,8 @@ TimeSkew: <div id="timeSkew"></div>
|
||||||
function cert() {
|
function cert() {
|
||||||
var url = 'http://localhost:8180/auth/realms/example/protocol/openid-connect/certs';
|
var url = 'http://localhost:8180/auth/realms/example/protocol/openid-connect/certs';
|
||||||
if (window.location.href.indexOf("8643") > -1) {
|
if (window.location.href.indexOf("8643") > -1) {
|
||||||
url = url.replace("8180","8543");
|
url = url.replace("8180", "8543");
|
||||||
url = url.replace("http","https");
|
url = url.replace("http", "https");
|
||||||
}
|
}
|
||||||
var req = new XMLHttpRequest();
|
var req = new XMLHttpRequest();
|
||||||
req.open('GET', url, true);
|
req.open('GET', url, true);
|
||||||
|
@ -245,8 +250,8 @@ TimeSkew: <div id="timeSkew"></div>
|
||||||
|
|
||||||
var url = "http://localhost:8180/auth/admin/realms/example/users";
|
var url = "http://localhost:8180/auth/admin/realms/example/users";
|
||||||
if (window.location.href.indexOf("8643") > -1) {
|
if (window.location.href.indexOf("8643") > -1) {
|
||||||
url = url.replace("8180","8543");
|
url = url.replace("8180", "8543");
|
||||||
url = url.replace("http","https");
|
url = url.replace("http", "https");
|
||||||
}
|
}
|
||||||
|
|
||||||
var req = new XMLHttpRequest();
|
var req = new XMLHttpRequest();
|
||||||
|
@ -269,6 +274,16 @@ TimeSkew: <div id="timeSkew"></div>
|
||||||
req.send(JSON.stringify(user));
|
req.send(JSON.stringify(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reentrancyCallback() {
|
||||||
|
keycloak.updateToken(60).success(function () {
|
||||||
|
event("First callback");
|
||||||
|
keycloak.updateToken(60).success(function () {
|
||||||
|
event("Second callback")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
var keycloak;
|
var keycloak;
|
||||||
|
|
||||||
function keycloakInit() {
|
function keycloakInit() {
|
||||||
|
@ -299,7 +314,11 @@ TimeSkew: <div id="timeSkew"></div>
|
||||||
event('Access token expired.');
|
event('Access token expired.');
|
||||||
};
|
};
|
||||||
|
|
||||||
var initOptions = {onLoad: document.getElementById("onLoad").value, flow: document.getElementById("flowSelect").value, responseMode: document.getElementById("responseModeSelect").value};
|
var initOptions = {
|
||||||
|
onLoad: document.getElementById("onLoad").value,
|
||||||
|
flow: document.getElementById("flowSelect").value,
|
||||||
|
responseMode: document.getElementById("responseModeSelect").value
|
||||||
|
};
|
||||||
keycloak.init(initOptions).success(function (authenticated) {
|
keycloak.init(initOptions).success(function (authenticated) {
|
||||||
output('Init Success (' + (authenticated ? 'Authenticated' : 'Not Authenticated') + ')');
|
output('Init Success (' + (authenticated ? 'Authenticated' : 'Not Authenticated') + ')');
|
||||||
}).error(function () {
|
}).error(function () {
|
||||||
|
|
|
@ -83,6 +83,8 @@ public class JSConsoleTestApp extends AbstractPageWithInjectedUrl {
|
||||||
private WebElement refreshTimeSkewButton;
|
private WebElement refreshTimeSkewButton;
|
||||||
@FindBy(xpath = "//button[text() = 'Create user']")
|
@FindBy(xpath = "//button[text() = 'Create user']")
|
||||||
private WebElement createUserButton;
|
private WebElement createUserButton;
|
||||||
|
@FindBy(xpath = "//button[text() = 'Reentrancy callback']")
|
||||||
|
private WebElement reentrancyCallbackButton;
|
||||||
|
|
||||||
@FindBy(id = "timeSkew")
|
@FindBy(id = "timeSkew")
|
||||||
private WebElement timeSkewValue;
|
private WebElement timeSkewValue;
|
||||||
|
@ -190,4 +192,8 @@ public class JSConsoleTestApp extends AbstractPageWithInjectedUrl {
|
||||||
public void sendCertRequest() {
|
public void sendCertRequest() {
|
||||||
certRequestButton.click();
|
certRequestButton.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void callReentrancyCallback() {
|
||||||
|
reentrancyCallbackButton.click();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -454,6 +454,18 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
|
||||||
.contains("location: " + authServerContextRootPage.toString() + "/auth/admin/realms/" + EXAMPLE + "/users/" + users.get(0).getId());
|
.contains("location: " + authServerContextRootPage.toString() + "/auth/admin/realms/" + EXAMPLE + "/users/" + users.get(0).getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void reentrancyCallbackTest() {
|
||||||
|
logInAndInit("standard");
|
||||||
|
|
||||||
|
jsConsoleTestAppPage.callReentrancyCallback();
|
||||||
|
|
||||||
|
waitUntilElement(jsConsoleTestAppPage.getEventsElement()).text().contains("First callback");
|
||||||
|
waitUntilElement(jsConsoleTestAppPage.getEventsElement()).text().contains("Second callback");
|
||||||
|
|
||||||
|
waitUntilElement(jsConsoleTestAppPage.getEventsElement()).text().not().contains("Auth Logout");
|
||||||
|
}
|
||||||
|
|
||||||
private void setImplicitFlowForClient() {
|
private void setImplicitFlowForClient() {
|
||||||
ClientResource clientResource = ApiUtil.findClientResourceByClientId(testRealmResource(), "js-console");
|
ClientResource clientResource = ApiUtil.findClientResourceByClientId(testRealmResource(), "js-console");
|
||||||
ClientRepresentation client = clientResource.toRepresentation();
|
ClientRepresentation client = clientResource.toRepresentation();
|
||||||
|
|
Loading…
Reference in a new issue