Hi, Kevin

I replied to batch mail, so this one went out of context.

-- 
Tair Sabirgaliev
Bee Software, LLP

On October 5, 2015 at 08:43:11, Tair Sabirgaliev (tair.sabirgaliev@bee.kz) wrote:

 
Here is what we did for angular 1.4 :

"use strict";

var module = angular.module('hello.world', ['ngRoute', 'ngResource']);

var auth = {};
var logout = function(){
    console.log('*** LOGOUT');
    auth.loggedIn = false;
    auth.authz = null;
    window.location = auth.logoutUrl;
};

angular.element(document).ready(["$http", function ($http) {

    var keycloakAuth = new Keycloak('js/keycloak.json');
    auth.loggedIn = false;


    keycloakAuth.init({ onLoad: 'login-required' }).success(function () {
        auth.loggedIn = true;
        auth.authz = keycloakAuth;
        auth.logoutUrl = keycloakAuth.authServerUrl + "/realms/demo/tokens/logout?redirect_uri=http://localhost:9080/hello-world/";
        module.factory('Auth', function() {
            return auth;
        });
        angular.bootstrap(document, ["hello.world"]);

    }).error(function () {
        window.location.reload();
    });

}]);

module.factory('authInterceptor', ["$q", "Auth", function($q, Auth) {
    return {
        'request': function (config) {
            var deferred = $q.defer();
            if (Auth.authz.token) {
                Auth.authz.updateToken(5).success(function() {
                    config.headers = config.headers || {};
                    config.headers.Authorization = 'Bearer ' + Auth.authz.token;

                    deferred.resolve(config);
                }).error(function() {
                    deferred.reject('Failed to refresh token');
                });
            }
            return deferred.promise;
        },
        'requestError': function(rejection) {
            return $q.reject(rejection);
        },

        'response': function(response) {
            return response;
        },

        'responseError': function(response) {

            if (response.status == 401) {
                console.log('session timeout?');
                logout();
            } else if (response.status == 403) {
                alert("Forbidden");
            } else if (response.status == 404) {
                alert("Not found");
            } else if (response.status) {
                console.log(response.status);
                if (response.data && response.data.errorMessage) {
                    alert(response.data.errorMessage);
                } else {
                    alert("An unexpected server error has occurred");
                }
            } else if (response === 'Failed to refresh token') {
                logout();
            }
            return $q.reject(response);
        }
    };
}]);

module.config(['$httpProvider', function($httpProvider) {
    $httpProvider.interceptors.push('authInterceptor');
}]);


--
Tair Sabirgaliev
Bee Software, LLP



On October 5, 2015 at 02:57:31, keycloak-user-request@lists.jboss.org (keycloak-user-request@lists.jboss.org(mailto:keycloak-user-request@lists.jboss.org)) wrote:

> Date: Sat, 3 Oct 2015 20:17:04 +0200(http://airmail.calendar/2015-10-04%2000:17:04%20GMT+6)
> From: "Kevin Hirschmann"
> Subject: [keycloak-user] angularjs example for 1.4
> To: "'keycloak-user'"
> Message-ID: <00cd01d0fe07$b4ab5d60$1e021820$@huebinet.de(mailto:00cd01d0fe07$b4ab5d60$1e021820$@huebinet.de)>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hello,
>
>
>
> I am trying to use the example provided here
>
>
>
> https://github.com/keycloak/keycloak/tree/master/examples/demo-template/angu
> lar-product-app
>
>
>
> to connect from an angularjs client to a REST Endpoint. Both frontend and
> backend are protected by keycloak.
>
> My problem is, that the example provided by the link above uses angularjs
> 1.2 and doesn?t work with newer versions.
>
> (see
> http://stackoverflow.com/questions/28212837/keycloak-unknown-provider-error)
>
>
>
> Has anyone on the mailing list been able to adapt the example to angular
> 1.4? What steps are necessary?
>
>
>
> Kind Regards
>
>
>
> Kevin Hirschmann
>
>
>
> HUEBINET Informationsmanagement GmbH & Co. KG
>
>
>
>
>
> Der Nachrichtenaustausch mit HUEBINET Informationsmanagement GmbH & Co. KG,
> Koblenz via E-Mail dient lediglich zu Informationszwecken.
> Rechtsgesch?ftliche Erkl?rungen mit verbindlichem Inhalt k?nnen ?ber dieses
> Medium nicht ausgetauscht werden, da die Manipulation von E-Mails durch
> Dritte nicht ausgeschlossen werden kann.
>
>
>
> Email communication with HUEBINET Informationsmanagement GmbH & Co. KG is
> only intended to provide information of a general kind, and shall not be
> used for any statement with binding contents in respect to legal relations.
> It is not totally possible to prevent a third party from manipulating emails
> and email contents.
>
>
>
>
>
>