-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move browser-extension-oauth2 to monorepo
- Loading branch information
Showing
25 changed files
with
3,297 additions
and
73 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,5 @@ | ||
{ | ||
"presets": [ | ||
["@babel/env", {"modules": false}] | ||
] | ||
} |
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,21 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es6": true | ||
}, | ||
"extends": ["eslint:recommended"], | ||
"parser": "babel-eslint", | ||
"plugins": [ | ||
"prettier" | ||
], | ||
"globals": { | ||
"browser": "readonly" | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2020, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"semi": "error" | ||
} | ||
} |
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,2 @@ | ||
node_modules | ||
dist |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Shuo Wu | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,64 @@ | ||
# browser-extension-oauth2 | ||
|
||
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. | ||
|
||
## Installation | ||
|
||
Please follow either of following options to use this module in your extension project. | ||
|
||
### Build extension with bundler like webpack | ||
|
||
```bash | ||
npm install browser-extension-oauth2 | ||
``` | ||
|
||
### Add bundle file directly in `manifest.json` | ||
|
||
- Clone repo | ||
|
||
- Install dependencies | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
- Build bundle | ||
|
||
```bash | ||
npm run build | ||
``` | ||
|
||
- Add `index.js` from dist folder to your extension project. Then | ||
|
||
## Development | ||
|
||
```bash | ||
npm install | ||
npm run dev | ||
``` | ||
|
||
## Examples | ||
|
||
```js | ||
import Oauth2 from 'browser-extension-oauth2' | ||
|
||
// Initial oauth2 instance | ||
const oauth2 = new Oauth2({ | ||
provider: '{provide name}', // Provider name, this will be used in redirectUrl and as storage key | ||
authorization_endpoint: '{oauth authorization_endpoint}', | ||
client_id: '{registered client id in idp}', | ||
scopes: ['{scope}'], // Scopes for api access | ||
api_base_url: '{api base url}' // Optional, only relative paths need to be provided if callApi method if this config exist | ||
}); | ||
|
||
// Call resource api, this method follows `fetch` API input with addtional renew token logic provided. | ||
// If no access token available, prompt will popup to ask for user's consent. | ||
oauth2.callApi('/protected-resource') | ||
.then(data => { | ||
// Handle resource | ||
}); | ||
``` | ||
|
||
### License | ||
|
||
MIT |
Oops, something went wrong.