Usage of Bearer Tokens in https request
Asked Answered
S

2

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

Shamanism answered 6/11, 2016 at 20:37 Comment(0)
M
30

Add auth to header in this way

var options = {        
        hostname: '<name of site>',
        port: 443,
        path: '<path>',
        method: 'GET',
        headers:{
            Authorization: ' Bearer <Token>'            
       }
};
Maldives answered 6/11, 2016 at 22:9 Comment(5)
This results in 403 Missing authorization With my code I had 403 Invalid authorisation Sadly didn't helped meShamanism
Can you provide mo information about this API. Any documentation? And code of you appMaldives
This is the API I'm using: (developer.clashofclans.com). In order to see the documentation you have to sign up.Shamanism
as I see in doc correct way - headers:{ Authorization: ' Bearer <Token>' }Maldives
@WernerderChamp You are wellcomeMaldives
Y
0

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

Yardmaster answered 6/11, 2016 at 20:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.