Skip to content

Commit e1feb3c

Browse files
authored
Add example and update linter (#11)
1 parent 37a0a2d commit e1feb3c

File tree

8 files changed

+131
-11
lines changed

8 files changed

+131
-11
lines changed

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
dist/
1+
dist/
2+
docs/

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = {
66
},
77
extends: [
88
'airbnb-base',
9+
'plugin:jsdoc/recommended',
910
],
1011
parserOptions: {
1112
ecmaVersion: 12,
@@ -14,4 +15,7 @@ module.exports = {
1415
rules: {
1516
'import/extensions': 0,
1617
},
18+
plugins: [
19+
'jsdoc',
20+
],
1721
};

.jsdoc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"opts": {
88
"destination": "docs",
99
"readme": "./README.md",
10-
"recurse": true
10+
"recurse": true,
11+
"tutorials": "./examples"
1112
}
1213
}

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
[![Logo][logo]][repo]
22

33
[![npm](https://img.shields.io/npm/v/dropbox-oauth-popup)](https://www.npmjs.com/package/dropbox-oauth-popup)
4+
![npm](https://img.shields.io/npm/dy/dropbox-oauth-popup)
5+
![jsDelivr hits (npm)](https://img.shields.io/jsdelivr/npm/hy/dropbox-oauth-popup)
6+
![GitHub package.json dependency version (prod)](https://img.shields.io/github/package-json/dependency-version/rogebrd/dropbox-oauth-popup/dropbox)
7+
48

59
This is a simple addition built onto the [Dropbox SDK][sdk] that allows for OAuth in the browser to be done via a popup window.
610

11+
You can view our documentation on [GitHub Pages][documentation].
12+
713
## Usage
814

915
1. Create a new instance of the `DropboxPopup` class
@@ -35,7 +41,7 @@ npm install --save-dev dropbox-oauth-popup
3541
Or you can use it directly in your browser be including the following tag
3642

3743
```
38-
<script src="https://cdn.jsdelivr.net/npm/dropbox-oauth-popup@1.2.0"></script>
44+
<script src="https://cdn.jsdelivr.net/npm/dropbox-oauth-popup@1.3.0"></script>
3945
```
4046

4147
## License
@@ -45,4 +51,5 @@ This package is distributed under the MIT license, please see [LICENSE][license]
4551
[logo]: https://repository-images.githubusercontent.com/304185097/6579e180-0fd1-11eb-9d46-91db905a363a
4652
[repo]: https://github.com/rogebrd/dropbox-oauth-popup
4753
[sdk]: https://github.com/dropbox/dropbox-sdk-js
54+
[documentation]: https://rogebrd.github.io/dropbox-oauth-popup
4855
[license]: https://github.com/rogebrd/dropbox-oauth-popup/blob/main/LICENSE

examples/browser.html

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@7/dist/polyfill.min.js"></script>
6+
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.3/fetch.js"></script>
7+
<script src="https://cdn.jsdelivr.net/npm/dropbox/dist/Dropbox-sdk.js"></script>
8+
<script src="https://cdn.jsdelivr.net/npm/dropbox-oauth-popup@1.3.0/dist/dropboxPopup.js"></script>
9+
</head>
10+
11+
<body>
12+
<div>
13+
<h1>Dropbox OAuth Popup Window</h1>
14+
<p>
15+
See the Dropbox OAuth Popup Window in action by clicking the run example button.
16+
This example will authenticate with your Dropbox account and use the token to fetch
17+
the current account using the `users.getCurrentAccount` endpoint. (Note, nothing is
18+
saved on our end, this is just a demo.)
19+
</p>
20+
<p>See the code on <a
21+
href="https://github.com/rogebrd/dropbox-oauth-popup/blob/main/examples/browser.html">GitHub</a></p>
22+
<button onclick="runAuth()">Run Example</button>
23+
<p id="result"></p>
24+
<script>
25+
const popup = new DropboxPopup({
26+
clientId: 'a04f1ghft6a45rn',
27+
clientSecret: 'tbjemcamktbyiy9',
28+
redirectUri: 'https://rogebrd.github.io/dropbox-oauth-popup/tutorial-browser.html'
29+
});
30+
function runAuth() {
31+
document.getElementById("result").innerHTML = "Waiting for auth...";
32+
popup.authUser((auth) => {
33+
const dbx = new Dropbox.Dropbox(auth);
34+
dbx.usersGetCurrentAccount()
35+
.then((response) => {
36+
document.getElementById("result").innerHTML = response.result;
37+
})
38+
.catch((error) => {
39+
document.getElementById("result").innerHTML = error;
40+
});
41+
});
42+
}
43+
</script>
44+
</div>
45+
</body>
46+
47+
</html>

package-lock.json

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dropbox-oauth-popup",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"registry": "npm",
55
"description": "This is a simple addition built onto the Dropbox SDK that allows for OAuth in the browser to be done via a popup window.",
66
"homepage": "https://github.com/rogebrd/dropbox-oauth-popup",
@@ -13,7 +13,8 @@
1313
"build": "rollup -c",
1414
"lint": "eslint *.js .",
1515
"lint-fix": "eslint *.js . --fix",
16-
"generate-docs": "jsdoc -c ./.jsdoc.json"
16+
"generate-docs": "jsdoc -c ./.jsdoc.json",
17+
"clean": "rm -rf docs dist"
1718
},
1819
"devDependencies": {
1920
"@babel/core": "^7.12.0",
@@ -22,6 +23,7 @@
2223
"eslint": "^7.11.0",
2324
"eslint-config-airbnb-base": "^14.2.0",
2425
"eslint-plugin-import": "^2.22.1",
26+
"eslint-plugin-jsdoc": "^30.6.5",
2527
"express": "^4.17.1",
2628
"jsdoc": "^3.6.6",
2729
"rollup": "^2.30.0",
@@ -57,4 +59,4 @@
5759
"front-end",
5860
"window"
5961
]
60-
}
62+
}

src/dropboxPopup.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ const popupName = 'Dropbox OAuth';
2323
/**
2424
* @class DropboxPopup
2525
* @classdesc The DropboxPopup class is to provide a simple popup window to preform OAuth in.
26-
* @arg {Object} options
27-
* @arg {String} [options.clientId] - The client id for your app.
28-
* @arg {String} [options.clientSecret] - The client secret for your app.
29-
* @arg {String} [options.redirectUri] - The redirect Uri to return to once auth is complete.
26+
* @param {object} options
27+
* @param {string} [options.clientId] - The client id for your app.
28+
* @param {string} [options.clientSecret] - The client secret for your app.
29+
* @param {string} [options.redirectUri] - The redirect Uri to return to once auth is complete.
3030
*/
3131
export default class DropboxPopup {
3232
constructor(options) {
@@ -42,6 +42,7 @@ export default class DropboxPopup {
4242

4343
/**
4444
* The main function to handle authentication via a popup window.
45+
*
4546
* @param {Function} callback - The callback function which will utilize the DropboxAuth object.
4647
* @returns {void}
4748
*/
@@ -58,8 +59,9 @@ export default class DropboxPopup {
5859

5960
/**
6061
* The function in charge of handling the redirect once the popup has completed.
62+
*
6163
* @param {MessageEvent} event - The incoming message from the popup window.
62-
* @return {void}
64+
* @returns {void}
6365
*/
6466
handleRedirect(event) {
6567
const { data } = event;

0 commit comments

Comments
 (0)