Werner der Champ Werner der Champ - 1 year ago 109
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>
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

Thanks in advance

Answer Source

Add auth to header in this way

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download