5

I am new to angular and I'm trying to pass an access token in my header, but I cant seem to get it right.

I have a curl request that works fine and I'm trying to get it in working in angular:

curl http://localhost:3000/api/v1/users -IH "Authorization: Token api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Angular $http call that isn't working

$http.get('http://localhost:3000/api/v1/users', {headers: {'api_key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'}}).then(function(response) {
                service.currentUser = response.data.user;
                console.log(service.currentUser);

Thanks!

1 Answer 1

10

Based on your curl I think the request should look like:

$http.get('http://localhost:3000/api/v1/users', 
    {headers: { Authorization: ' Token api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxx'}})
    .then(function(response) {
            service.currentUser = response.data.user;
            console.log(service.currentUser);
    });
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, surprised I missed that. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.