From f29aff4bed92fc5794ad17eb144aaa9084137b87 Mon Sep 17 00:00:00 2001 From: Libor Krzyzanek Date: Wed, 7 Oct 2015 13:53:25 +0200 Subject: [PATCH] Add 'register' and 'createRegisterUrl' methods to Javascript Adapter API. fixes #KEYCLOAK-1904 --- .../en/en-US/modules/javascript-adapter.xml | 15 +++++++++++ examples/js-console/README.md | 2 +- .../js-console/src/main/webapp/index.html | 2 ++ integration/js/src/main/resources/keycloak.js | 27 +++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/docbook/auth-server-docs/reference/en/en-US/modules/javascript-adapter.xml b/docbook/auth-server-docs/reference/en/en-US/modules/javascript-adapter.xml index 2e9f941ed8..33d62dca2d 100755 --- a/docbook/auth-server-docs/reference/en/en-US/modules/javascript-adapter.xml +++ b/docbook/auth-server-docs/reference/en/en-US/modules/javascript-adapter.xml @@ -209,6 +209,7 @@ new Keycloak({ url: 'http://localhost/auth', realm: 'myrealm', clientId: 'myApp' redirectUri - specifies the uri to redirect to after login prompt - can be set to 'none' to check if the user is logged in already (if not logged in, a login form is not displayed) loginHint - used to pre-fill the username/email field on the login form + action - if value is 'register' then user is redirected to registration page, otherwise to login page @@ -246,6 +247,20 @@ new Keycloak({ url: 'http://localhost/auth', realm: 'myrealm', clientId: 'myApp' + + register(options) + + Redirects to registration form. It's a shortcut for doing login with option action = 'register' + Options are same as login method but 'action' is overwritten to 'register' + + + + createRegisterUrl(options) + + Returns the url to registration page. It's a shortcut for doing createRegisterUrl with option action = 'register' + Options are same as createLoginUrl method but 'action' is overwritten to 'register' + + accountManagement() diff --git a/examples/js-console/README.md b/examples/js-console/README.md index 749c0f3612..fa9a02d192 100644 --- a/examples/js-console/README.md +++ b/examples/js-console/README.md @@ -12,6 +12,6 @@ Open the Keycloak admin console, click on Add Realm, click on 'Choose a JSON fil Deploy the JS Console to Keycloak by running: - mvn install jboss-as:deploy + mvn install wildfly:deploy Open the console at http://localhost:8080/js-console and login with username: 'user', and password: 'password'. diff --git a/examples/js-console/src/main/webapp/index.html b/examples/js-console/src/main/webapp/index.html index d85b63b811..2cca0f8d16 100644 --- a/examples/js-console/src/main/webapp/index.html +++ b/examples/js-console/src/main/webapp/index.html @@ -7,6 +7,7 @@
+ @@ -18,6 +19,7 @@ +

Result

diff --git a/integration/js/src/main/resources/keycloak.js b/integration/js/src/main/resources/keycloak.js index f384e7b5ea..d189a361f8 100755 --- a/integration/js/src/main/resources/keycloak.js +++ b/integration/js/src/main/resources/keycloak.js @@ -183,6 +183,18 @@ return url; } + kc.register = function (options) { + return adapter.register(options); + } + + kc.createRegisterUrl = function(options) { + if (!options) { + options = {}; + } + options.action = 'register'; + return kc.createLoginUrl(options); + } + kc.createAccountUrl = function(options) { var url = getRealmUrl() + '/account' @@ -760,6 +772,11 @@ return createPromise().promise; }, + register: function(options) { + window.location.href = kc.createRegisterUrl(options); + return createPromise().promise; + }, + accountManagement : function() { window.location.href = kc.createAccountUrl(); return createPromise().promise; @@ -858,6 +875,16 @@ return promise.promise; }, + register : function() { + var registerUrl = kc.createRegisterUrl(); + var ref = window.open(registerUrl, '_blank', 'location=no'); + ref.addEventListener('loadstart', function(event) { + if (event.url.indexOf('http://localhost') == 0) { + ref.close(); + } + }); + }, + accountManagement : function() { var accountUrl = kc.createAccountUrl(); var ref = window.open(accountUrl, '_blank', 'location=no');