1

I am new to Node.js, OAuth.

I am developing a web app using Nodejs. My application is interacting with the third party API to get data. Per documentation of API "All methods in this third party API take OAUTH authentication parameters in request header"(that's it no more details)

I decided to use Passport module of Node.JS to achieve this(http://passportjs.org/guide/oauth/).

My Problem is I am unable to understand how to proceed with this. Let say we have an API method "http://api.travel/getAllLocation" which returns all locations where user can travel.

Can someone pls help here by providing example how to use NodeJS, Passport to get required data from webservice .

[Update] Have found this answer which is trying to achieve the same thing. But how to achieve the same using Passport How to send the OAuth request in Node

2
  • Have you tried the examples on the passportjs website? Your link to the api does not point correctly either. Commented Dec 22, 2014 at 10:36
  • Thanks Kevin. API URL is just taken for an example. It's not valid one. Commented Dec 22, 2014 at 11:08

1 Answer 1

1

It sounds to me as if you're trying to use Oauth to access someone else's API correct? If that's the case, you need to interact with the API by doing this:

  • Requesting an Oauth token given an API key.
  • Putting that token into your HTTP Authorization header so that the third-party API can identify and authenticate you.

The way you can request an API token (typically) via the command line using cURL is as follows:

$ curl -v --user api_key_id:api_key_secret -X POST https://api.something.com/v1/auth?grant_type=client_credentials

This will typically return some sort of token (hopefully a JSON web token!) that you can then use to identify yourself. Here's an example cURL request that properly specifies a token:

$ curl -v -H "Authorization: Bearer tokenhere" https://api.something.com/v1/blah

Using Node, you can craft these HTTP requests with the https://github.com/request/request library. Again, if you link us to the exact docs, I can help ya further =)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.