16

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

Werner der Champ
  • 361
  • 1
  • 3
  • 12

2 Answers2

28

Add auth to header in this way

var options = {        
        hostname: '<name of site>',
        port: 443,
        path: '<path>',
        method: 'GET',
        headers:{
            Authorization: ' Bearer <Token>'            
       }
};
Denis Lisitskiy
  • 1,285
  • 11
  • 15
0

auth:'Bearer <Token>' should be header, not query

galkin
  • 5,264
  • 3
  • 34
  • 51