Skip to content

Commit a7bfc10

Browse files
committed
Initial Commit
0 parents  commit a7bfc10

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+27241
-0
lines changed

.circleci/config.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: 2
2+
jobs:
3+
build:
4+
docker:
5+
- image: cypress/browsers:chrome67
6+
working_directory: ~/repo
7+
steps:
8+
- checkout
9+
- run: npm ci
10+
- run: npm run build
11+
- run: npm run test
12+
- run: npm run test:integration
13+
- run: npm run test:es-check
14+
- run: npm run print-bundle-size

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.rpt2_cache
2+
node_modules
3+
dist
4+
coverage
5+
stats.html
6+
cypress/screenshots
7+
cypress/videos

.npmignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
node_modules
2+
src
3+
test
4+
static
5+
.gitignore
6+
.npmignore
7+
rollup.config.js
8+
tsconfig.json
9+
.rpt2_cache
10+
.vscode

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"printWidth": 80
4+
}

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"search.exclude": {
4+
"**/node_modules": true,
5+
"**/bower_components": true,
6+
"**/dist": true,
7+
"**/.rpt2_cache": true,
8+
"**/docs": true
9+
}
10+
}

CONTRIBUTING.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Contribution
2+
3+
Please read [Auth0's contribution guidelines](GENERAL-CONTRIBUTING.md).
4+
5+
## Environment setup
6+
7+
- Make sure you have node and npm installed
8+
- Run `npm install` to install dependencies
9+
- Follow the local development steps below to get started
10+
11+
## Local development
12+
13+
- `npm install`: install dependencies
14+
- `npm start`: starts development http server at [http://localhost:3000](http://localhost:3000) with live reload enabled
15+
- `npm run test`: run unit tests
16+
- `npm run test:watch`: run unit tests continuously
17+
- `npm run test:integration`: run integration tests
18+
- `npm run test:watch:integration`: run integration tests continuously
19+
- `npm run build`: build distribution files
20+
- `npm run test:es-check`: check if distribution files are compatible with browsers
21+
- `npm run print-bundle-size`: print the final bundle size of distribution files
22+
23+
## Testing
24+
25+
### Adding tests
26+
27+
- Unit tests go inside [\_\_tests\_\_](https://github.com/auth0/auth0-spa-js/tree/master/__tests__)
28+
- Integration tests go inside [cypress/integration](https://github.com/auth0/auth0-spa-js/tree/master/cypress/integration)
29+
30+
### Running tests
31+
32+
Run unit and integration tests before opening a PR:
33+
34+
```bash
35+
npm run test
36+
npm run test:integration
37+
```
38+
39+
Also include any information about essential manual tests.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 Auth0, Inc. <[email protected]> (http://auth0.com)
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.

README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# @auth0/auth0-spa-js
2+
3+
Auth0 SDK for Single Page Applications using [Authorization Code Grant Flow with PKCE](https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce).
4+
5+
[![CircleCI](https://circleci.com/gh/auth0/auth0-spa-js.svg?style=svg)](https://circleci.com/gh/auth0/auth0-spa-js)
6+
[![License](http://img.shields.io/:license-mit-blue.svg?style=flat)](https://opensource.org/licenses/MIT)
7+
8+
## Table of Contents
9+
10+
Make sure this is updated based on the sections included:
11+
12+
- [Documentation](#documentation)
13+
- [Installation](#installation)
14+
- [Getting Started](#getting-started)
15+
- [Contributing](#contributing)
16+
- [Support + Feedback](#support--feedback)
17+
- [Vulnerability Reporting](#vulnerability-reporting)
18+
- [What is Auth0](#what-is-auth0)
19+
- [License](#license)
20+
21+
## Documentation
22+
23+
- See the [API reference](https://auth0.github.io/auth0-spa-js/)
24+
25+
## Installation
26+
27+
From the CDN:
28+
29+
```html
30+
<script src="https://cdn.auth0.com/js/auth0-spa-js/1.0.0/auth0-spa-js.production.js"></script>
31+
```
32+
33+
Using [npm](https://npmjs.org):
34+
35+
```sh
36+
npm install @auth0/auth0-spa-js
37+
```
38+
39+
Using [yarn](https://yarnpkg.com):
40+
41+
```sh
42+
yarn add @auth0/auth0-spa-js
43+
```
44+
45+
## Getting Started
46+
47+
```js
48+
import createAuth0Client from '@auth0/auth0-spa-js';
49+
50+
const auth0 = await createAuth0Client({
51+
domain: 'auth.brucke.club',
52+
client_id: 'wLSIP47wM39wKdDmOj6Zb5eSEw3JVhVp'
53+
});
54+
await auth0.loginWithPopup();
55+
const user = await auth0.getUser();
56+
const accessToken = await auth0.getTokenSilently();
57+
```
58+
59+
## Contributing
60+
61+
We appreciate feedback and contribution to this repo! Before you get started, please see the following:
62+
63+
- [Auth0's general contribution guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md)
64+
- [Auth0's code of conduct guidelines](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md)
65+
- [This repo's contribution guide](CONTRIBUTING.md)
66+
67+
## Support + Feedback
68+
69+
- Use [Issues](https://github.com/auth0/auth0-spa-js/issues) for code-level support
70+
- Use [Community](https://community.auth0.com/) for usage, questions, specific cases
71+
72+
## Vulnerability Reporting
73+
74+
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.
75+
76+
## What is Auth0?
77+
78+
Auth0 helps you to easily:
79+
80+
- 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.)
81+
- log in users with username/password databases, passwordless, or multi-factor authentication
82+
- link multiple user accounts together
83+
- generate signed JSON Web Tokens to authorize your API calls and flow the user identity securely
84+
- access demographics and analytics detailing how, when, and where users are logging in
85+
- enrich user profiles from other data sources using customizable JavaScript rules
86+
87+
[Why Auth0?](https://auth0.com/why-auth0)
88+
89+
## License
90+
91+
This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.

__tests__/__mocks__/storage.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const internalStorage = {};
2+
3+
export const get = <T extends Object>(key: string) => {
4+
const value = internalStorage[key];
5+
if (typeof value === 'undefined') {
6+
return;
7+
}
8+
return <T>JSON.parse(value);
9+
};
10+
export const save = (key: string, value: any, options: any) => {
11+
internalStorage[key] = JSON.stringify(value);
12+
};
13+
export const remove = (key: string) => {
14+
internalStorage[key] = undefined;
15+
};

__tests__/cache.test.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import Cache from '../src/cache';
2+
3+
describe('cache', () => {
4+
let cache: Cache;
5+
beforeEach(() => {
6+
cache = new Cache();
7+
jest.useFakeTimers();
8+
});
9+
afterEach(jest.useRealTimers);
10+
it('returns undefined when there is no data', () => {
11+
expect(cache.get({ audience: 'a', scope: 's' })).toBeUndefined();
12+
});
13+
it('builds key correctly', () => {
14+
cache.save({
15+
audience: 'the_audiene',
16+
scope: 'the_scope',
17+
id_token: 'idtoken',
18+
access_token: 'accesstoken',
19+
expires_in: 1,
20+
decodedToken: {
21+
claims: { exp: 1, name: 'Test' },
22+
user: { name: 'Test' }
23+
}
24+
});
25+
expect(Object.keys(cache.cache)[0]).toBe('the_audiene::the_scope');
26+
});
27+
it('builds key correctly', () => {
28+
cache.save({
29+
audience: 'the_audiene',
30+
scope: 'the_scope',
31+
id_token: 'idtoken',
32+
access_token: 'accesstoken',
33+
expires_in: 1,
34+
decodedToken: {
35+
claims: { name: 'Test' },
36+
user: { name: 'Test' }
37+
}
38+
});
39+
expect(Object.keys(cache.cache)[0]).toBe('the_audiene::the_scope');
40+
});
41+
it('expires after `expires_in` when `expires_in` < `user.exp`', () => {
42+
cache.save({
43+
audience: 'the_audiene',
44+
scope: 'the_scope',
45+
id_token: 'idtoken',
46+
access_token: 'accesstoken',
47+
expires_in: 1,
48+
decodedToken: {
49+
claims: { name: 'Test', exp: new Date().getTime() / 1000 + 2 },
50+
user: { name: 'Test' }
51+
}
52+
});
53+
jest.advanceTimersByTime(1001);
54+
expect(Object.keys(cache.cache).length).toBe(0);
55+
});
56+
it('expires after `user.exp` when `user.exp` < `expires_in`', () => {
57+
cache.save({
58+
audience: 'the_audiene',
59+
scope: 'the_scope',
60+
id_token: 'idtoken',
61+
access_token: 'accesstoken',
62+
expires_in: 2,
63+
decodedToken: {
64+
claims: { name: 'Test', exp: new Date().getTime() / 1000 + 1 },
65+
user: { name: 'Test' }
66+
}
67+
});
68+
jest.advanceTimersByTime(1001);
69+
expect(Object.keys(cache.cache).length).toBe(0);
70+
});
71+
});

0 commit comments

Comments
 (0)