How to integrate Ember.JS and Keycloak SSO system

旧时模样 提交于 2020-01-25 13:03:28

问题


My question is quite simple : does anybody know how to integrate Ember.JS and Keycloak (the SSO system) ? We currently face a problem using the Keycloak JS Bower library (https://github.com/keycloak/keycloak-js-bower) to redirect users to Keycloak own login page, and to generally integrate Ember.JS with Keycloak. Our problems are :

Double page reload on page reloading,

401 unauthorized HTTP code on login to the Ember App.

Thanks for your (precious) support.


回答1:


You can use script JS: Check that you have script in your keycloak: https://yourdoamin.com/auth/js/keycloak.js

If you have, add this code to your login page:

<head>
    <script src="https://yourdoamin.com/auth/js/keycloak.js"></script>
    <script>
        var keycloak = Keycloak({
            "realm": "relam_name",
            "url": "https://yourdomain.com/auth",
            "ssl-required": "external",
            "resource": "client_id",
            "verify-token-audience": true,
            "credentials": {
                "secret": "secret_code"
            },
            "use-resource-role-mappings": true,
            "confidential-port": 0,
            "policy-enforcer": {},
            "onLoad":'login-required',
            "clientId": "client_id"
        });

        var keycloak = Keycloak();
        keycloak.init().success(function(authenticated) {
            console.log(keycloak);
            alert(authenticated ? 'authenticated' : 'not authenticated');
        }).error(function() {
            alert('failed to initialize');
        });
    </script>
</head>

In console.log(keycloak); Keycloak return token and other information about user.

More info:

Keycloak JavaScript API to get current logged in user

JavaScript Adapter

MicroProfile JWT Authentication with Keycloak and React




回答2:


There are a couple ember cli addons that deal with Keycloak and Ember integration:

https://www.npmjs.com/package/ember-cli-keycloak

https://www.npmjs.com/package/ember-keycloak-auth



来源:https://stackoverflow.com/questions/37610430/how-to-integrate-ember-js-and-keycloak-sso-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!