Werner der Champ Werner der Champ - 27 days ago 10
Node.js Question

Usage of Bearer Tokens in https request

I'm trying to connect to an API using 'auth' in the options. Currently it looks like this:

var options = {
hostname: '<name of site>',
port: 443,
path: '<path>',
auth:'Bearer <Token>',
method: 'GET'
};


However, I get Status Code 403 if I execute the request. When I put the following URL in the browser, it works:

https://<Host Name+ Path>?authorization=Bearer%20<Token>


I've already tried to change auth into
Authorization=Bearer <Token>
and
Authorisation:Bearer <Token>
but it didn't changed anything.

I'm probably just setting up the authorisation part not correctly, but couldn't find any info how
auth
works

Thanks in advance

Answer

Add auth to header in this way

var options = {        
        hostname: '<name of site>',
        port: 443,
        path: '<path>',
        method: 'GET',
        headers:{
            Authorization: ' Bearer <Token>'            
       }
};

Comments