最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Meteor basic HTTP authentication - Stack Overflow

programmeradmin5浏览0评论

Need to connect to an external api: Vogogo.The hard part is converting the curl example into a valid Meteor HTTP.get call. Now here is the code I came up with

apiversionVogogo = 'v3';

Vogogo.listAllCustomers = function() {
    HTTP.get('/' + apiversionVogogo + '/customers', {
            headers: {
                'Authorization': {
                    user: clientID,
                    clientsecret: apisecret
                }
            }
        },
        function(error, result) {
            if (error) {
                console.log(error);
            } else {
                console.log(result);
            }
        });
    return;
}

The response is an error message:

error_message: 'HTTP Authorization expected"'

Can someone help me rewrite this basic HTTP authentication into a default format? In the docs an example is given with CURL.

curl -X GET '' \
 --user clientsecret: \
 -H "Content-Type: application/json"

Need to connect to an external api: Vogogo.The hard part is converting the curl example into a valid Meteor HTTP.get call. Now here is the code I came up with

apiversionVogogo = 'v3';

Vogogo.listAllCustomers = function() {
    HTTP.get('https://api.vogogo./' + apiversionVogogo + '/customers', {
            headers: {
                'Authorization': {
                    user: clientID,
                    clientsecret: apisecret
                }
            }
        },
        function(error, result) {
            if (error) {
                console.log(error);
            } else {
                console.log(result);
            }
        });
    return;
}

The response is an error message:

error_message: 'HTTP Authorization expected"'

Can someone help me rewrite this basic HTTP authentication into a default format? In the docs an example is given with CURL.

curl -X GET 'https://api.vogogo./v3/customers' \
 --user clientsecret: \
 -H "Content-Type: application/json"
Share Improve this question edited Jul 24, 2015 at 11:31 Fullhdpixel asked Jul 24, 2015 at 11:25 FullhdpixelFullhdpixel 8231 gold badge13 silver badges28 bronze badges 3
  • 1 Did you try setting the auth paramater in the options field instead of actually setting the Authorization in the headers? From Docs : auth String HTTP basic authentication string of the form "username:password" – Nate Commented Jul 24, 2015 at 12:41
  • so that your request would look like HTTP.get('https://api.vogogo./' + apiversionVogogo + '/customers', { auth : "clientID:apisecret"}) – Nate Commented Jul 24, 2015 at 12:42
  • Thanks Nate! That worked like a charm :) – Fullhdpixel Commented Jul 24, 2015 at 12:56
Add a ment  | 

1 Answer 1

Reset to default 10

Use the auth parameter in the options field instead of actually setting the Authorization in the headers. From the Docs : auth String HTTP basic authentication string of the form "username:password". You're request would look like:

HTTP.get('https://api.vogogo./' + apiversionVogogo + '/customers', { auth : "clientID:apisecret"})
发布评论

评论列表(0)

  1. 暂无评论