Skip to content
This repository was archived by the owner on Jan 24, 2026. It is now read-only.

oAuth and File Upload support#451

Draft
Pezmc wants to merge 6 commits intosimplyspoke:masterfrom
Pezmc:custom-build
Draft

oAuth and File Upload support#451
Pezmc wants to merge 6 commits intosimplyspoke:masterfrom
Pezmc:custom-build

Conversation

@Pezmc
Copy link
Copy Markdown

@Pezmc Pezmc commented Jun 22, 2020

This is a very old fork (~2015), just opening the draft PR to refer to it in #85

There are two ways to use oauth, by passing in a valid access token
when instantiating Node-Harvest or using the oAuth flow, calling
this.parseAccessCode() with an access code provided by Harvest after
hitting the URL in this.getAccessTokenURL().

Example usage:

```
        var harvest_with_token = new Harvest({
	    subdomain: config.harvest_oauth.subdomain,
	    access_token: access_token
	});

	var TimeTracking = harvest.TimeTracking;

	TimeTracking.daily({}, function(err, tasks) {
	    if (err) throw new Error(err);

		console.log('Loaded tasks using passed in auth_token!');
	});
```

or

```
var harvest = new Harvest({
    subdomain: config.harvest_oauth.subdomain,
    identifier: config.harvest_oauth.client_id,
    secret: config.harvest_oauth.secret,
    redirect_uri: config.harvest_oauth.redirect_uri
});

console.log('Visit the following and paste the access code param from
the url here', harvest.getAccessTokenURL());

rl.question("Code from the URL: ", function(answer) {
	rl.close();

	harvest.parseAccessCode(answer.trim(), function(access_token) {
		console.log('Grabbed the access token', access_token);

		var TimeTracking = harvest.TimeTracking;

		TimeTracking.daily({}, function(err, tasks) {
		    if (err) throw new Error(err);

			console.log('Loaded tasks using oauth!');
		});
	})
});
```
Usage example:

```
    var options = {
    	id: config.expense_id,
    	file: {
    		path: 'path/to-my-image.jpeg',
    		originalname: 'original-name-of-my-image.jpeg'
    	}
    }

    Expenses.attachReceipt(options, function(err, reply) {
    	if (err) throw new Error(err);

    	console.log(reply);
    });
```
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant