mercredi 6 mai 2015

How to inject services to monitor authentication and storage status?

I'm using Angular.js to build a client side application with Restangular. The problem is, I implemented a digest authentication with a wsse header which i have to generate at each request to my REST Server.

I saw that Restangular provide a function : addFullRequestInterceptor().

So now, i'm trying to use it inside my RestangularProvider to configure it in this file restangular.js :

'use strict';

// Config Restangular
app.config(function(RestangularProvider) {
  RestangularProvider.setBaseUrl(applicationConfig.SERVER_URL);
  RestangularProvider.setDefaultHeaders({'Content-Type': 'application/json'});
  RestangularProvider.addFullRequestInterceptor(function (element, operation, route, url, headers, params, httpConfig) {
    $http.defaults.headers.common['X-WSSE'] = TokenHandler.getCredentials(AuthHandler.authentication.user.username,AuthHandler.authentication.secret); // Here is my header generation.
    return {
      element: element,
      headers: headers,
      params: params,
      httpConfig: httpConfig
    };
  });
});

But i have an injection problem and i can't find out how to inject my TokenHandler service & my AuthHandler service to be able to know if the user is already loggedin or not and if he has localstroage or not.

Thanks for the help ;)

Aucun commentaire :

Enregistrer un commentaire