Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a7bfc10
Showing
70 changed files
with
27,241 additions
and
0 deletions.
There are no files selected for viewing
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,14 @@ | ||
version: 2 | ||
jobs: | ||
build: | ||
docker: | ||
- image: cypress/browsers:chrome67 | ||
working_directory: ~/repo | ||
steps: | ||
- checkout | ||
- run: npm ci | ||
- run: npm run build | ||
- run: npm run test | ||
- run: npm run test:integration | ||
- run: npm run test:es-check | ||
- run: npm run print-bundle-size |
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,7 @@ | ||
.rpt2_cache | ||
node_modules | ||
dist | ||
coverage | ||
stats.html | ||
cypress/screenshots | ||
cypress/videos |
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,10 @@ | ||
node_modules | ||
src | ||
test | ||
static | ||
.gitignore | ||
.npmignore | ||
rollup.config.js | ||
tsconfig.json | ||
.rpt2_cache | ||
.vscode |
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 @@ | ||
docs |
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,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"printWidth": 80 | ||
} |
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,10 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"search.exclude": { | ||
"**/node_modules": true, | ||
"**/bower_components": true, | ||
"**/dist": true, | ||
"**/.rpt2_cache": true, | ||
"**/docs": true | ||
} | ||
} |
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,39 @@ | ||
# Contribution | ||
|
||
Please read [Auth0's contribution guidelines](GENERAL-CONTRIBUTING.md). | ||
|
||
## Environment setup | ||
|
||
- Make sure you have node and npm installed | ||
- Run `npm install` to install dependencies | ||
- Follow the local development steps below to get started | ||
|
||
## Local development | ||
|
||
- `npm install`: install dependencies | ||
- `npm start`: starts development http server at [http://localhost:3000](http://localhost:3000) with live reload enabled | ||
- `npm run test`: run unit tests | ||
- `npm run test:watch`: run unit tests continuously | ||
- `npm run test:integration`: run integration tests | ||
- `npm run test:watch:integration`: run integration tests continuously | ||
- `npm run build`: build distribution files | ||
- `npm run test:es-check`: check if distribution files are compatible with browsers | ||
- `npm run print-bundle-size`: print the final bundle size of distribution files | ||
|
||
## Testing | ||
|
||
### Adding tests | ||
|
||
- Unit tests go inside [\_\_tests\_\_](https://github.com/auth0/auth0-spa-js/tree/master/__tests__) | ||
- Integration tests go inside [cypress/integration](https://github.com/auth0/auth0-spa-js/tree/master/cypress/integration) | ||
|
||
### Running tests | ||
|
||
Run unit and integration tests before opening a PR: | ||
|
||
```bash | ||
npm run test | ||
npm run test:integration | ||
``` | ||
|
||
Also include any information about essential manual tests. |
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 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2018 Auth0, Inc. <support@auth0.com> (http://auth0.com) | ||
|
||
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,91 @@ | ||
# @auth0/auth0-spa-js | ||
|
||
Auth0 SDK for Single Page Applications using [Authorization Code Grant Flow with PKCE](https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce). | ||
|
||
[![CircleCI](https://circleci.com/gh/auth0/auth0-spa-js.svg?style=svg)](https://circleci.com/gh/auth0/auth0-spa-js) | ||
[![License](http://img.shields.io/:license-mit-blue.svg?style=flat)](https://opensource.org/licenses/MIT) | ||
|
||
## Table of Contents | ||
|
||
Make sure this is updated based on the sections included: | ||
|
||
- [Documentation](#documentation) | ||
- [Installation](#installation) | ||
- [Getting Started](#getting-started) | ||
- [Contributing](#contributing) | ||
- [Support + Feedback](#support--feedback) | ||
- [Vulnerability Reporting](#vulnerability-reporting) | ||
- [What is Auth0](#what-is-auth0) | ||
- [License](#license) | ||
|
||
## Documentation | ||
|
||
- See the [API reference](https://auth0.github.io/auth0-spa-js/) | ||
|
||
## Installation | ||
|
||
From the CDN: | ||
|
||
```html | ||
<script src="https://cdn.auth0.com/js/auth0-spa-js/1.0.0/auth0-spa-js.production.js"></script> | ||
``` | ||
|
||
Using [npm](https://npmjs.org): | ||
|
||
```sh | ||
npm install @auth0/auth0-spa-js | ||
``` | ||
|
||
Using [yarn](https://yarnpkg.com): | ||
|
||
```sh | ||
yarn add @auth0/auth0-spa-js | ||
``` | ||
|
||
## Getting Started | ||
|
||
```js | ||
import createAuth0Client from '@auth0/auth0-spa-js'; | ||
|
||
const auth0 = await createAuth0Client({ | ||
domain: 'auth.brucke.club', | ||
client_id: 'wLSIP47wM39wKdDmOj6Zb5eSEw3JVhVp' | ||
}); | ||
await auth0.loginWithPopup(); | ||
const user = await auth0.getUser(); | ||
const accessToken = await auth0.getTokenSilently(); | ||
``` | ||
|
||
## Contributing | ||
|
||
We appreciate feedback and contribution to this repo! Before you get started, please see the following: | ||
|
||
- [Auth0's general contribution guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md) | ||
- [Auth0's code of conduct guidelines](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md) | ||
- [This repo's contribution guide](CONTRIBUTING.md) | ||
|
||
## Support + Feedback | ||
|
||
- Use [Issues](https://github.com/auth0/auth0-spa-js/issues) for code-level support | ||
- Use [Community](https://community.auth0.com/) for usage, questions, specific cases | ||
|
||
## Vulnerability Reporting | ||
|
||
Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/whitehat) details the procedure for disclosing security issues. | ||
|
||
## What is Auth0? | ||
|
||
Auth0 helps you to easily: | ||
|
||
- implement authentication with multiple identity providers, including social (e.g., Google, Facebook, Microsoft, LinkedIn, GitHub, Twitter, etc), or enterprise (e.g., Windows Azure AD, Google Apps, Active Directory, ADFS, SAML, etc.) | ||
- log in users with username/password databases, passwordless, or multi-factor authentication | ||
- link multiple user accounts together | ||
- generate signed JSON Web Tokens to authorize your API calls and flow the user identity securely | ||
- access demographics and analytics detailing how, when, and where users are logging in | ||
- enrich user profiles from other data sources using customizable JavaScript rules | ||
|
||
[Why Auth0?](https://auth0.com/why-auth0) | ||
|
||
## License | ||
|
||
This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info. |
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,15 @@ | ||
export const internalStorage = {}; | ||
|
||
export const get = <T extends Object>(key: string) => { | ||
const value = internalStorage[key]; | ||
if (typeof value === 'undefined') { | ||
return; | ||
} | ||
return <T>JSON.parse(value); | ||
}; | ||
export const save = (key: string, value: any, options: any) => { | ||
internalStorage[key] = JSON.stringify(value); | ||
}; | ||
export const remove = (key: string) => { | ||
internalStorage[key] = undefined; | ||
}; |
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,71 @@ | ||
import Cache from '../src/cache'; | ||
|
||
describe('cache', () => { | ||
let cache: Cache; | ||
beforeEach(() => { | ||
cache = new Cache(); | ||
jest.useFakeTimers(); | ||
}); | ||
afterEach(jest.useRealTimers); | ||
it('returns undefined when there is no data', () => { | ||
expect(cache.get({ audience: 'a', scope: 's' })).toBeUndefined(); | ||
}); | ||
it('builds key correctly', () => { | ||
cache.save({ | ||
audience: 'the_audiene', | ||
scope: 'the_scope', | ||
id_token: 'idtoken', | ||
access_token: 'accesstoken', | ||
expires_in: 1, | ||
decodedToken: { | ||
claims: { exp: 1, name: 'Test' }, | ||
user: { name: 'Test' } | ||
} | ||
}); | ||
expect(Object.keys(cache.cache)[0]).toBe('the_audiene::the_scope'); | ||
}); | ||
it('builds key correctly', () => { | ||
cache.save({ | ||
audience: 'the_audiene', | ||
scope: 'the_scope', | ||
id_token: 'idtoken', | ||
access_token: 'accesstoken', | ||
expires_in: 1, | ||
decodedToken: { | ||
claims: { name: 'Test' }, | ||
user: { name: 'Test' } | ||
} | ||
}); | ||
expect(Object.keys(cache.cache)[0]).toBe('the_audiene::the_scope'); | ||
}); | ||
it('expires after `expires_in` when `expires_in` < `user.exp`', () => { | ||
cache.save({ | ||
audience: 'the_audiene', | ||
scope: 'the_scope', | ||
id_token: 'idtoken', | ||
access_token: 'accesstoken', | ||
expires_in: 1, | ||
decodedToken: { | ||
claims: { name: 'Test', exp: new Date().getTime() / 1000 + 2 }, | ||
user: { name: 'Test' } | ||
} | ||
}); | ||
jest.advanceTimersByTime(1001); | ||
expect(Object.keys(cache.cache).length).toBe(0); | ||
}); | ||
it('expires after `user.exp` when `user.exp` < `expires_in`', () => { | ||
cache.save({ | ||
audience: 'the_audiene', | ||
scope: 'the_scope', | ||
id_token: 'idtoken', | ||
access_token: 'accesstoken', | ||
expires_in: 2, | ||
decodedToken: { | ||
claims: { name: 'Test', exp: new Date().getTime() / 1000 + 1 }, | ||
user: { name: 'Test' } | ||
} | ||
}); | ||
jest.advanceTimersByTime(1001); | ||
expect(Object.keys(cache.cache).length).toBe(0); | ||
}); | ||
}); |
Oops, something went wrong.