Skip to content

Commit 41439f7

Browse files
committed
chore: move browser-extension-oauth2 to monorepo
1 parent 329fc07 commit 41439f7

25 files changed

+3297
-73
lines changed

package-lock.json

+126-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
["@babel/env", {"modules": false}]
4+
]
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es6": true
5+
},
6+
"extends": ["eslint:recommended"],
7+
"parser": "babel-eslint",
8+
"plugins": [
9+
"prettier"
10+
],
11+
"globals": {
12+
"browser": "readonly"
13+
},
14+
"parserOptions": {
15+
"ecmaVersion": 2020,
16+
"sourceType": "module"
17+
},
18+
"rules": {
19+
"semi": "error"
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Shuo Wu
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# browser-extension-oauth2
2+
3+
This module provides wrapper around browser.identity API for Oauth2.0 implicit flow. This module not only handles retrieving and renewing access token from authorization endpoints and properly cache it in `browser.storage.local`, but also provide enhanced fetch functon, `callApi`, to access protected resources with access token properly binded in headers.
4+
5+
## Installation
6+
7+
Please follow either of following options to use this module in your extension project.
8+
9+
### Build extension with bundler like webpack
10+
11+
```bash
12+
npm install browser-extension-oauth2
13+
```
14+
15+
### Add bundle file directly in `manifest.json`
16+
17+
- Clone repo
18+
19+
- Install dependencies
20+
21+
```bash
22+
npm install
23+
```
24+
25+
- Build bundle
26+
27+
```bash
28+
npm run build
29+
```
30+
31+
- Add `index.js` from dist folder to your extension project. Then
32+
33+
## Development
34+
35+
```bash
36+
npm install
37+
npm run dev
38+
```
39+
40+
## Examples
41+
42+
```js
43+
import Oauth2 from 'browser-extension-oauth2'
44+
45+
// Initial oauth2 instance
46+
const oauth2 = new Oauth2({
47+
provider: '{provide name}', // Provider name, this will be used in redirectUrl and as storage key
48+
authorization_endpoint: '{oauth authorization_endpoint}',
49+
client_id: '{registered client id in idp}',
50+
scopes: ['{scope}'], // Scopes for api access
51+
api_base_url: '{api base url}' // Optional, only relative paths need to be provided if callApi method if this config exist
52+
});
53+
54+
// Call resource api, this method follows `fetch` API input with addtional renew token logic provided.
55+
// If no access token available, prompt will popup to ask for user's consent.
56+
oauth2.callApi('/protected-resource')
57+
.then(data => {
58+
// Handle resource
59+
});
60+
```
61+
62+
### License
63+
64+
MIT

0 commit comments

Comments
 (0)