Updated js example
This commit is contained in:
parent
7d6f88f617
commit
a40568ed54
2 changed files with 7 additions and 8 deletions
|
@ -10,7 +10,8 @@
|
||||||
clientId : 'test-app',
|
clientId : 'test-app',
|
||||||
clientSecret : 'password',
|
clientSecret : 'password',
|
||||||
baseUrl : 'http://localhost:8081/auth-server',
|
baseUrl : 'http://localhost:8081/auth-server',
|
||||||
realm : 'test'
|
realm : 'test',
|
||||||
|
redirectUri : 'http://localhost/js'
|
||||||
});
|
});
|
||||||
|
|
||||||
if (keycloak.authenticated) {
|
if (keycloak.authenticated) {
|
||||||
|
|
|
@ -4,7 +4,8 @@ window.keycloak = (function () {
|
||||||
baseUrl: null,
|
baseUrl: null,
|
||||||
clientId: null,
|
clientId: null,
|
||||||
clientSecret: null,
|
clientSecret: null,
|
||||||
realm: null
|
realm: null,
|
||||||
|
redirectUri: null
|
||||||
};
|
};
|
||||||
|
|
||||||
kc.init = function (c) {
|
kc.init = function (c) {
|
||||||
|
@ -30,12 +31,9 @@ window.keycloak = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
kc.login = function () {
|
kc.login = function () {
|
||||||
var clientId = encodeURIComponent(config.clientId);
|
var state = createUUID();
|
||||||
var redirectUri = encodeURIComponent(window.location.href);
|
var url = config.baseUrl + '/rest/realms/' + encodeURIComponent(config.realm) + '/tokens/login?response_type=code&client_id='
|
||||||
var state = encodeURIComponent(createUUID());
|
+ encodeURIComponent(config.clientId) + '&redirect_uri=' + encodeURIComponent(config.redirectUri) + '&state=' + encodeURIComponent(state);
|
||||||
var realm = encodeURIComponent(config.realm);
|
|
||||||
var url = config.baseUrl + '/rest/realms/' + realm + '/tokens/login?response_type=code&client_id=' + clientId + '&redirect_uri=' + redirectUri
|
|
||||||
+ '&state=' + state;
|
|
||||||
|
|
||||||
sessionStorage.state = state;
|
sessionStorage.state = state;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue