Skip to content

Commit 89714c3

Browse files
committed
fix #11 add interactive workflow
1 parent 18fe3aa commit 89714c3

File tree

5 files changed

+1028
-56
lines changed

5 files changed

+1028
-56
lines changed

README.md

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,30 @@
22

33
[![NPM](https://nodei.co/npm/dropbox-refresh-token.png?compact=true)](https://npmjs.org/package/dropbox-refresh-token)
44

5+
## Quickstart
56

6-
## About Dropbox long-lived tokens (and offline mode access)
7-
Dropbox didn't provide anymore (since On September 30th, 2021) long-live access token from dropbox portal ([src](https://dropbox.tech/developers/migrating-app-permissions-and-access-tokens#retiring-legacy-tokens)).
7+
HowTo get Dropbox refresh-token and/or access-token (console interactive mode)
88

9-
In order to access offline to dropbox services without having to login, you will need:
9+
````bash
10+
npm i -g dropbox-refresh-token@latest
11+
get_refresh_token
12+
# follow instructions
13+
````
14+
NB: `get_refresh_token` binary has some alias : `drt` and `dropbox_get_refresh_token`.
15+
16+
NB2: if you have cloned this project you could instead invoke this with `./bin/get_refresh_token.js`
17+
18+
## Context : about Dropbox tokens
19+
20+
Short context about Dropbox long-lived tokens (and offline mode access).
21+
22+
Dropbox didn't provide anymore (since On September 30th, 2021) long-live access token from dropbox portal ([src](https://dropbox.tech/developers/migrating-app-permissions-and-access-tokens#retiring-legacy-tokens)). This was the way to use token for offline applications.
23+
24+
Now, in order to access offline to dropbox services without having to login,
25+
you will need an offline **refresh-token**.
26+
And with this token you application is able to request a short-lived access token to call Dropbox API.
27+
28+
Here are the steps:
1029
1) to ask an **access-code for an "offline" token-access-type**
1130
- this step require to login to allow application access.
1231
2) get a (long-lived) **refresh-token** with this access-code.
@@ -29,29 +48,40 @@ Having this **refresh-token** in "offline" mode (without login requirement) you
2948

3049
## Project features
3150
Feature for a given DropBox app (appKey, appSecret).
32-
- (step 1) build login url to allow application access and then retrieve short-lived access code for an "offline" token-access-type (appKey only)
51+
- (step 1) build login url to allow application access and then retrieve short-lived access code for an "offline" token-access-type (appKey only)
52+
`getShortLivedAccessCodeUrlViaLoginUrl(appKey)`
3353
- (step 2) provide method to call Dropbox API that ask (long-lived) refresh-token from this short-lived access code (accessCode, appKey, appSecret).
54+
`getRefreshToken(shortLivedAccessCode, appKey, appSecret, logToken = false)`
3455
- (step 3++) provide method to call Dropbox API that ask a fresh (short-lived) access token from a valid refresh-token (refreshToke, appKey, appSecret).
56+
`refreshAccessToken(refresh_token, appKey, appSecret, logToken = false)`
3557

3658
## HowTo use "dropbox-refresh-token" library
3759

38-
- Setup
60+
- Setup this project as dependency
3961
````bash
4062
npm i dropbox-refresh-token
4163
````
4264

4365
- Integration examples
4466
````javascript
45-
import {isSet, getShortLivedAccessCodeUrlViaLoginUrl, getRefreshToken, refreshAccessToken} from "dropbox-refresh-token";
67+
import {
68+
isSet, getShortLivedAccessCodeUrlViaLoginUrl,
69+
getRefreshToken, refreshAccessToken
70+
} from "dropbox-refresh-token";
4671

47-
import {isSet, getCurrentAccount, isAccessTokenValid} from "dropbox-refresh-token";
72+
import {
73+
isSet, getCurrentAccount, isAccessTokenValid
74+
} from "dropbox-refresh-token";
4875

4976
````
5077

51-
## Console mode step-by-step to retrieve Dropbox RefreshToken
78+
### Another example - step-by-step to retrieve Dropbox RefreshToken
5279

5380
<!> original idea is [FranklinThaker/Dropbox-API-Uninterrupted-Access](https://github.com/FranklinThaker/Dropbox-API-Uninterrupted-Access) which provide (webApplication mode)
5481

82+
This workflow rely on environment variables and require project install
83+
(cf. § quickstart for more modern workflow)
84+
5585
````bash
5686
git clone https://github.com/boly38/dropbox-refresh-token.git
5787
cd dropbox-refresh-token
@@ -71,3 +101,5 @@ node src/dropbox_is_token_valid.js
71101
![Repobeats](https://repobeats.axiom.co/api/embed/381c29252a790e5069c7a80418665d22f4dbfaab.svg "Repobeats analytics image")
72102

73103
<small>provided by [Repobeats](https://repobeats.axiom.co/)</small>
104+
105+

bin/get_refresh_token.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env node
2+
import {interactiveGetRefreshToken} from "../src/dropbox_refresh_token_interactive.js";
3+
4+
await interactiveGetRefreshToken();

0 commit comments

Comments
 (0)