VikramK
VikramK

Reputation: 663

Using Passport module in Nodejs for OAuth

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

Upvotes: 1

Views: 383

Answers (1)

rdegges
rdegges

Reputation: 33864

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 =)

Upvotes: 1

Related Questions