authentication Token is always null

时间:2015-08-07 02:24:24

标签: angularjs rest authentication

I'm developping application with Rest Service, Angularjs and Token based authentication and that works fine when I have a single application containing client and server code. but when I have client and server in different sides that code returns always authToken null :

private String extractAuthTokenFromRequest(HttpServletRequest httpRequest)
{

    /* Get token from header */
    String authToken = httpRequest.getHeader("X-Auth-Token");

    /* If token not found get it from request parameter */
    if (authToken == null) {
        authToken = httpRequest.getParameter("token");
    }

    return authToken;
}

Any help please?

EDIT:

  $httpProvider.interceptors.push(function ($q, $rootScope, $location) {
            return {
                'request': function(config) {
                    var isRestCall = config.url.indexOf('rest') == 0;
                    if (isRestCall && angular.isDefined($rootScope.authToken)) {
                        var authToken = $rootScope.authToken;
                        if (exampleAppConfig.useAuthTokenHeader) {
                            config.headers['X-Auth-Token'] = authToken;
                        } else {
                            config.url = config.url + "?token=" + authToken;
                        }
                    }
                    return config || $q.when(config);
                }
            };
        }
    );

0 个答案:

没有答案