-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8145620
commit 63240a3
Showing
5 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
.ideo | ||
node_modules |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
Authenticate on the v2 version of the Harvest API | ||
*/ | ||
const express = require('express'); | ||
const session = require('express-session'); | ||
const grant = require('grant-express'); | ||
const request = require('request'); | ||
|
||
module.exports = function(data,callback) { | ||
const app = express(); | ||
|
||
app.use(session({secret: data.APP_SECRET, saveUninitialized: true, resave: true})); | ||
app.use(grant({ | ||
defaults: { | ||
protocol: data.PROTOCOL, | ||
host: data.HOST | ||
}, | ||
harvestv2: { | ||
"authorize_url": "https://id.getharvest.com/oauth2/authorize", | ||
"access_url": "https://id.getharvest.com/api/v2/oauth2/token", | ||
"oauth": 2, | ||
key: data.CLIENT_ID, | ||
secret: data.CLIENT_SECRET, | ||
"callback": "/auth/harvestv2" | ||
} | ||
})); | ||
|
||
app.get('/auth/harvestv2', (req, res) => { | ||
|
||
const options = { | ||
url: 'https://id.getharvest.com/api/v2/accounts', | ||
headers: { | ||
'Authorization': 'Bearer ' + req.query.access_token, | ||
'User-Agent': data.APP_NAME | ||
}, | ||
json:true | ||
}; | ||
|
||
request(options, (qerr, qres, qbody) => { | ||
|
||
if (qerr) { | ||
res.send("Error requsting harvest accounts: "+qerr); | ||
return console.log(qerr); | ||
} | ||
|
||
callback(res, {tokens: req.query, accounts: qbody}); | ||
}); | ||
}); | ||
|
||
return app; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
# Authenticate via the Harvest API | ||
# Authenticate via the Harvest API | ||
|
||
## Requirements | ||
|
||
You need [Express](https://expressjs.com/) to use this module | ||
|
||
## How to use | ||
|
||
Install using npm: "npm i harvest-auth" | ||
|
||
Take a look at at the [example implementation]("examples/existing-express.js") |