Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get storage to work with custom authentication API #115

Closed
kevinfanomena opened this issue Feb 11, 2015 · 4 comments
Closed

Can't get storage to work with custom authentication API #115

kevinfanomena opened this issue Feb 11, 2015 · 4 comments

Comments

@kevinfanomena
Copy link

Hi, I'm trying to use ng-token-auth to handle authentication with a custom authentication token API but can't get the storage (either cookie or local storage) to work after a call to submitLogin.

After a successful login (with password+email) my API responds with :

{ auth_token: "M8q6YXe3z4G1v5bx.3cfdd0778cdc3c6fded89426753cb06f4da314e395790fa5edee01750eb0c1d5", expires: "2015-02-18T16:36:35+00:00" }

I configured ng-auth-token thusly:

$authProvider.configure({
    apiUrl: '/api',
    signOutUrl: '/auth/signout',
    emailRegistrationPath: '/auth/register',
    emailSignInPath: '/auth/signin',
    confirmationSuccessUrl: window.location.href,
    storage: 'localStorage',
    authProviderPaths: {
        facebook: '/auth/facebook'
    },
    parseExpiry: function(headers) {
        return headers.expires;
    },
    handleLoginResponse: function(response) {
        return response;
    },
    handleAccountResponse: function(response) {
        return response;
    },
    handleTokenValidationResponse: function(response) {
        return response;
    }
});

And my sign in function looks like

$scope.signin = function(credentials) {
    $auth.submitLogin(credentials)
        .then(function(resp) {
            console.log('then: ');
            console.dir(resp);
        })
        .catch(function(resp) {
            console.log('err: ');
            console.log(resp);
        });
};

The only thing being written to local storage is {currentConfigName: "default"}. Am I doing something wrong? I've been trying out all kinds of different settings but I just can't get it to work. Any help would be greatly appreciated.

@beneshed
Copy link

+1

@lynndylanhurley
Copy link
Owner

@kevinfanomena - did you read the section on using custom header formats?

The headers of each response to the API are checked against the keys of the tokenFormat hash in the config. It looks like you're using a non-default auth header (auth_token) - try passing this to the config:

tokenFormat: {
  "auth_token": "{{ token }}"
}

@railslauncher
Copy link

@kevinfanomena You are returning the token details in response body(JSON). But token information should be in the response headers.

If you set the following headers it will work.

Access-Token, Uid, Expiry, Token-Type. Because I faced same issue.

@kevinfanomena
Copy link
Author

Yes, I was returning the token in the response body and not the headers. Thanks for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants