Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 1.7.0 beta branch #419

Merged
merged 42 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
559d2c9
Export types from global TypeScript file.
maxswa Dec 17, 2019
eceac8f
Fix BaseLoginOptions JSDoc.
maxswa Dec 17, 2019
29441d1
Fix Auth0Client export and integration tests.
maxswa Dec 18, 2019
5cc83a3
Prevent breaking changes with type and import.
maxswa Dec 18, 2019
e46d3ca
Add export for Auth0Client type.
maxswa Dec 19, 2019
7f277d1
Merge branch 'master' into export-global-types
Jan 17, 2020
f596300
Merge branch 'master' into export-global-types
Jan 24, 2020
a13a3e6
[SDK-1178] Local Storage caching mechanism (#303)
Jan 6, 2020
49f0edd
[SDK-1179] Support for rotating refresh tokens (#315)
Jan 8, 2020
6f95174
Release 1.7.0-beta.1 (#327)
Jan 8, 2020
e06e3c3
Fixed issue with cache not retaining refresh token (#333)
Jan 16, 2020
ab6def6
Prepare 1.7.0-beta.2 (#334)
Jan 16, 2020
cdbdb4e
Wrapped InMemoryCache implementation in a closure (#337)
Jan 24, 2020
3733206
Reinstated lock on getTokenSilently
Jan 26, 2020
2ef25e6
Fixed up code + tests after rebase
Jan 26, 2020
02ecd83
Merge branch 'release/rtr' into export-global-types
Jan 26, 2020
2ed1faa
Fixed up types
Jan 26, 2020
53509dc
Merge remote-tracking branch 'origin/master' into release/rtr
Feb 7, 2020
3b4cf56
Removed undesirables from the docs generation
Feb 7, 2020
7660aea
Merge branch 'master' into release/rtr
Feb 11, 2020
175cb47
[SDK-1352] Removed setTimeout cache removal in favour of removal-on-r…
Feb 14, 2020
966f6a2
[SDK-1279] getTokenSilently retry logic (#336)
Feb 17, 2020
ecff936
[SDK-1352] Stop checking `isAuthenticated` cookie on initialization w…
Feb 17, 2020
4e5ad57
Merge branch 'master' into release/rtr
Feb 17, 2020
5a64d45
Release 1.7.0-beta.3 (#358)
Feb 17, 2020
2cd8340
Fix error in library type definitions (#367)
devoto13 Mar 2, 2020
d8a6f06
[SDK-1386] Fall back to iframe method if no refresh token is availabl…
Mar 3, 2020
0b8cfc1
Release 1.7.0-beta.4 (#370)
Mar 3, 2020
a877501
Merge remote-tracking branch 'origin/master' into release/rtr
Mar 19, 2020
bfb95e6
Merge remote-tracking branch 'origin/master' into release/rtr
Mar 19, 2020
891a749
Updated cache configuration instructions in the readme
Mar 24, 2020
5863664
Removed unused cacheStrategy param from buildAuthorizeUrl
Mar 24, 2020
ed1f8a3
[SDK-1379] Export constructor (#385)
adamjmcgrath Mar 26, 2020
2a8e6f6
Release 1.7.0-beta.5 (#393)
adamjmcgrath Mar 26, 2020
2db03fc
Merge remote-tracking branch 'origin/master' into release/rtr
Apr 7, 2020
e0ae15c
[SDK-1507] Dependency upgrade (#405)
Apr 7, 2020
d1528fe
[SDK-1516] Web Workers (#409)
adamjmcgrath Apr 14, 2020
707ec5a
Updated readme with info on refresh tokens (#415)
Apr 15, 2020
55d479e
Implemented fallback to iframe when given specific audience (#414)
Apr 15, 2020
7b04165
Check if iframe is still in body before removing (#399)
paulfalgout Apr 15, 2020
609067a
Check if source of event exists before closing it (#410)
gerritdeperrit Apr 15, 2020
9ab3402
Removed unused error import
Apr 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: cypress/browsers:chrome67
- image: cypress/browsers:node12.13.0-chrome80-ff74
working_directory: ~/repo
steps:
- checkout
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ coverage
stats.html
cypress/screenshots
cypress/videos
.release
.release
.idea
36 changes: 36 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest (current file)",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["${fileBasenameNoExtension}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true
},
{
"type": "node",
"request": "launch",
"name": "Jest (all tests)",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true
},
{
"type": "node",
"request": "launch",
"name": "Build",
"program": "${workspaceFolder}/node_modules/.bin/rollup",
"args": ["-m", "-c"],
"console": "integratedTerminal"
}
]
}
49 changes: 49 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
# Change Log

## [v1.7.0-beta.5](https://github.com/auth0/auth0-spa-js/tree/v1.7.0-beta.5) (2020-03-26)

[Full Changelog](https://github.com/auth0/auth0-spa-js/compare/v1.7.0-beta.4...v1.7.0-beta.5)

**Changed**

- [SDK-1379] Export constructor [\#385](https://github.com/auth0/auth0-spa-js/pull/385) ([adamjmcgrath](https://github.com/adamjmcgrath))

## [v1.7.0-beta.4](https://github.com/auth0/auth0-spa-js/tree/v1.7.0-beta.4) (2020-03-03)

[Full Changelog](https://github.com/auth0/auth0-spa-js/compare/v1.7.0-beta.3...v1.7.0-beta.4)

**Changed**

- [SDK-1386] Fall back to iframe method if no refresh token is available [\#364](https://github.com/auth0/auth0-spa-js/pull/364) ([stevehobbsdev](https://github.com/stevehobbsdev))

**Fixed**

- Fix error in library type definitions [\#367](https://github.com/auth0/auth0-spa-js/pull/367) ([devoto13](https://github.com/devoto13))

## [v1.7.0-beta.3](https://github.com/auth0/auth0-spa-js/tree/v1.7.0-beta.3) (2020-02-17)

[Full Changelog](https://github.com/auth0/auth0-spa-js/compare/v1.7.0-beta.2...v1.7.0-beta.3)

**Added**

- Export types from global TypeScript file. [\#310](https://github.com/auth0/auth0-spa-js/pull/310) ([maxswa](https://github.com/maxswa))

**Changed**

- [SDK-1352] Removed setTimeout cache removal in favour of removal-on-read [\#354](https://github.com/auth0/auth0-spa-js/pull/354) ([stevehobbsdev](https://github.com/stevehobbsdev))
- [SDK-1352] Stop checking `isAuthenticated` cookie on initialization when using local storage [\#352](https://github.com/auth0/auth0-spa-js/pull/352) ([stevehobbsdev](https://github.com/stevehobbsdev))
- [SDK-1279] getTokenSilently retry logic [\#336](https://github.com/auth0/auth0-spa-js/pull/336) ([stevehobbsdev](https://github.com/stevehobbsdev))

## [v1.7.0-beta.2](https://github.com/auth0/auth0-spa-js/tree/v1.7.0-beta.2) (2020-01-16)

[Full Changelog](https://github.com/auth0/auth0-spa-js/compare/v1.7.0-beta.1...v1.7.0-beta.2)

**Changed**

- Fixed issue with cache not retaining refresh token [\#333](https://github.com/auth0/auth0-spa-js/pull/333) ([stevehobbsdev](https://github.com/stevehobbsdev))

## [v1.7.0-beta.1](https://github.com/auth0/auth0-spa-js/tree/v1.7.0-beta.1) (2020-01-08)

**Added**

- Ability to use either an in-memory cache (the default) or localstorage to store tokens - [stevehobbsdev](https://github.com/stevehobbsdev) - https://github.com/auth0/auth0-spa-js/pull/303
- Added support for rotating refresh tokens - [stevehobbsdev](https://github.com/stevehobbsdev) - https://github.com/auth0/auth0-spa-js/pull/315

## [v1.6.5](https://github.com/auth0/auth0-spa-js/tree/v1.6.5) (2020-03-19)

[Full Changelog](https://github.com/auth0/auth0-spa-js/compare/v1.6.4...v1.6.5)
Expand Down
12 changes: 6 additions & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ pipeline {
agent {
label 'crew-brucke'
}

tools {
nodejs '10.15.1'
nodejs '12.9.1'
}

options {
timeout(time: 10, unit: 'MINUTES')
}

stages {
stage('SharedLibs') {
steps {
Expand Down Expand Up @@ -52,10 +52,10 @@ pipeline {
}
}
}

post {
cleanup {
deleteDir()
}
}
}
}
80 changes: 67 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Auth0 SDK for Single Page Applications using [Authorization Code Grant Flow with
From the CDN:

```html
<script src="https://cdn.auth0.com/js/auth0-spa-js/1.6/auth0-spa-js.production.js"></script>
<script src="https://cdn.auth0.com/js/auth0-spa-js/1.7/auth0-spa-js.production.js"></script>
```

Using [npm](https://npmjs.org):
Expand Down Expand Up @@ -56,17 +56,35 @@ import createAuth0Client from '@auth0/auth0-spa-js';
const auth0 = await createAuth0Client({
domain: '<AUTH0_DOMAIN>',
client_id: '<AUTH0_CLIENT_ID>',
redirect_uri: '<MY_CALLBACK_URL>'
redirect_uri: '<MY_CALLBACK_URL>',
});

//with promises
createAuth0Client({
domain: '<AUTH0_DOMAIN>',
client_id: '<AUTH0_CLIENT_ID>',
redirect_uri: '<MY_CALLBACK_URL>'
}).then(auth0 => {
redirect_uri: '<MY_CALLBACK_URL>',
}).then((auth0) => {
//...
});

//or, you can just instantiate the client on it's own
import { Auth0Client } from '@auth0/auth0-spa-js';

const auth0 = new Auth0Client({
domain: '<AUTH0_DOMAIN>',
client_id: '<AUTH0_CLIENT_ID>',
redirect_uri: '<MY_CALLBACK_URL>',
});

//if you do this, you'll need to check the session yourself
try {
await getTokenSilently();
} catch (error) {
if (error.error !== 'login_required') {
throw error;
}
}
```

### 1 - Login
Expand Down Expand Up @@ -102,9 +120,9 @@ document.getElementById('login').addEventListener('click', () => {

//in your callback route (<MY_CALLBACK_URL>)
window.addEventListener('load', () => {
auth0.handleRedirectCallback().then(redirectResult => {
auth0.handleRedirectCallback().then((redirectResult) => {
//logged in. you can get the user profile like this:
auth0.getUser().then(user => {
auth0.getUser().then((user) => {
console.log(user);
});
});
Expand All @@ -124,8 +142,8 @@ document.getElementById('call-api').addEventListener('click', async () => {
const result = await fetch('https://myapi.com', {
method: 'GET',
headers: {
Authorization: `Bearer ${accessToken}`
}
Authorization: `Bearer ${accessToken}`,
},
});
const data = await result.json();
console.log(data);
Expand All @@ -135,16 +153,16 @@ document.getElementById('call-api').addEventListener('click', async () => {
document.getElementById('call-api').addEventListener('click', () => {
auth0
.getTokenSilently()
.then(accessToken =>
.then((accessToken) =>
fetch('https://myapi.com', {
method: 'GET',
headers: {
Authorization: `Bearer ${accessToken}`
}
Authorization: `Bearer ${accessToken}`,
},
})
)
.then(result => result.json())
.then(data => {
.then((result) => result.json())
.then((data) => {
console.log(data);
});
});
Expand All @@ -164,6 +182,42 @@ document.getElementById('logout').addEventListener('click', () => {
});
```

### Data caching options

The SDK can be configured to cache ID tokens and access tokens either in memory or in local storage. The default is in memory. This setting can be controlled using the `cacheLocation` option when creating the Auth0 client.

To use the in-memory mode, no additional options need are required as this is the default setting. To configure the SDK to cache data using local storage, set `cacheLocation` as follows:

```js
await createAuth0Client({
domain: '<AUTH0_DOMAIN>',
client_id: '<AUTH0_CLIENT_ID>',
redirect_uri: '<MY_CALLBACK_URL>',
cacheLocation: 'localstorage', // valid values are: 'memory' or 'localstorage'
});
```

**Important:** This feature will allow the caching of data **such as ID and access tokens** to be stored in local storage. Exercising this option changes the security characteristics of your application and **should not be used lightly**. Extra care should be taken to mitigate against XSS attacks and minimize the risk of tokens being stolen from local storage.

### Refresh Tokens

Refresh tokens can be used to request new access tokens. [Read more about how our refresh tokens work for browser-based applications](https://auth0.com/docs/tokens/concepts/refresh-token-rotation) to help you decide whether or not you need to use them.

To enable the use of refresh tokens, set the `useRefreshTokens` option to `true`:

```js
await createAuth0Client({
domain: '<AUTH0_DOMAIN>',
client_id: '<AUTH0_CLIENT_ID>',
redirect_uri: '<MY_CALLBACK_URL>',
useRefreshTokens: true,
});
```

Using this setting will cause the SDK to automatically send the `offline_access` scope to the authorization server. Refresh tokens will then be used to exchange for new access tokens instead of using a hidden iframe, and calls the `/oauth/token` endpoint directly. This means that the SDK does not rely on third-party cookies when using refresh tokens.

**Note** This configuration option requires Rotating Refresh Tokens to be [enabled for your Auth0 Tenant](https://auth0.com/docs/tokens/guides/configure-refresh-token-rotation).

## Contributing

We appreciate feedback and contribution to this repo! Before you get started, please see the following:
Expand Down
Loading