Skip to content

Commit 2e1bfe6

Browse files
committed
merged
2 parents ec6efd4 + 60dccdd commit 2e1bfe6

27 files changed

+480
-12589
lines changed

CHANGELOG.md

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,13 @@
22

33
## Lates features
44

5-
See [Release Notes](https://github.com/manfredsteyer/angular-oauth2-oidc/releases)
5+
See [Release Notes](https://github.com/manfredsteyer/angular-oauth2-oidc/releases) for details on each release.
66

7-
## New Features in Version 2.1
8-
- New Config API (the original one is still supported)
9-
- New convenience methods in OAuthService to streamline default tasks:
10-
- ``setupAutomaticSilentRefresh()``
11-
- ``loadDiscoveryDocumentAndTryLogin()``
12-
- Single Sign out through Session Status Change Notification according to the OpenID Connect Session Management specs. This means, you can be notified when the user logs out using at the login provider.
13-
- Possibility to define the ValidationHandler, the Config as well as the OAuthStorage via DI
14-
- Better structured documentation
7+
## Older versions
158

16-
## New Features in Version 2
17-
- Token Refresh for Implicit Flow by implementing "silent refresh"
18-
- Validating the signature of the received id_token
19-
- Providing Events via the observable ``events``.
20-
- The event ``token_expires`` can be used together with a silent refresh to automatically refresh a token when/ before it expires (see also property ``timeoutFactor``).
9+
Since Angular 5, versions of this library matched up with the Angular version.
10+
So versions 5.x were released while Angular 5 was out, the 6.x versions during Angular 6, etc.
11+
If you need to support a specific old version of Angular, you can consider using a version of the library that lines up.
2112

22-
## Breaking Changes in Version 2
23-
- The property ``oidc`` defaults to ``true``.
24-
- If you are just using oauth2, you have to set ``oidc`` to ``false``. Otherwise, the validation of the user profile will fail!
25-
- By default, ``sessionStorage`` is used. To use ``localStorage`` call method setStorage
26-
- Demands using https as OIDC and OAuth2 relay on it. This rule can be relaxed using the property ``requireHttps``, e. g. for local testing.
27-
- Demands that every url provided by the discovery document starts with the issuer's url. This can be relaxed by using the property ``strictDiscoveryDocumentValidation``.
13+
For older release notes check the repository version history, or above-linked release notes.
14+
For even older versions, check out [the old change log](https://github.com/manfredsteyer/angular-oauth2-oidc/blob/5d676101c6118d6fa01bfa05b17fb4a58490eaf7/CHANGELOG.md).

README.md

Lines changed: 72 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,25 @@ Support for OAuth 2 and OpenId Connect (OIDC) in Angular.
77
## Credits
88

99
- [generator-angular2-library](https://github.com/jvandemo/generator-angular2-library) for scaffolding an Angular library
10-
- [jsrasign](https://kjur.github.io/jsrsasign/) until version 5: For validating token signature and for hashing; beginning with version 6, we are using browser APIs to minimize our bundle size
11-
- [Identity Server](https://github.com/identityserver) (used for testing with an .NET/.NET Core Backend)
10+
- [jsrasign](https://kjur.github.io/jsrsasign/) for validating token signature and for hashing
11+
- [Identity Server](https://github.com/identityserver) for testing with an .NET/.NET Core Backend
1212
- [Keycloak (Redhat)](http://www.keycloak.org/) for testing with Java
1313

1414
## Resources
1515

16-
- Sources and Sample:
17-
https://github.com/manfredsteyer/angular-oauth2-oidc
18-
19-
- Source Code Documentation
20-
https://manfredsteyer.github.io/angular-oauth2-oidc/docs
16+
- Sources and Sample: [https://github.com/manfredsteyer/angular-oauth2-oidc](https://github.com/manfredsteyer/angular-oauth2-oidc)
17+
- Source Code Documentation: [https://manfredsteyer.github.io/angular-oauth2-oidc/docs](https://manfredsteyer.github.io/angular-oauth2-oidc/docs)
18+
- Community-provided sample implementation: [https://github.com/jeroenheijmans/sample-angular-oauth2-oidc-with-auth-guards/](https://github.com/jeroenheijmans/sample-angular-oauth2-oidc-with-auth-guards/)
2119

2220
## Tested Environment
2321

24-
Successfully tested with **Angular 8**, **Angular 7**, and its Router, PathLocationStrategy as well as HashLocationStrategy and CommonJS-Bundling via webpack. At server side we've used IdentityServer (.NET/ .NET Core) and Redhat's Keycloak (Java).
22+
Successfully tested with **Angular 9** and its Router, PathLocationStrategy as well as HashLocationStrategy and CommonJS-Bundling via webpack. At server side we've used IdentityServer (.NET / .NET Core) and Redhat's Keycloak (Java).
23+
24+
**Angular 9**: Use 9.x versions of this library.
25+
26+
**Angular 8**: Use 8.x versions of this library.
27+
28+
**Angular 7**: Use 7.x versions of this library.
2529

2630
**Angular 6**: Use Version 4.x of this library. Version 4.x was tested with Angular 6. You can also try the newer version 5.x of this library which has a much smaller bundle size.
2731

@@ -30,21 +34,23 @@ Successfully tested with **Angular 8**, **Angular 7**, and its Router, PathLocat
3034
## Release Cycle
3135

3236
- We plan one major release for each Angular version
33-
- Will contain new features
34-
- Will contain bug fixes and PRs
37+
- Will contain new features
38+
- Will contain bug fixes and PRs
3539
- Critical Bugfixes on demand
3640

3741
## Contributions
42+
3843
- Feel free to file pull requests
3944
- The closed issues contain some ideas for PRs and enhancements (see labels)
4045
- If you want to contribute to the docs, you can do so in the `docs-src` folder. Make sure you update `summary.json` as well. Then generate the docs with the following commands:
4146

42-
```
47+
``` sh
4348
npm install -g @compodoc/compodoc
4449
npm run docs
4550
```
4651

47-
# Features
52+
## Features
53+
4854
- Logging in via Implicit Flow (where a user is redirected to Identity Provider)
4955
- Logging in via Code Flow + PKCE
5056
- "Logging in" via Password Flow (where a user enters their password into the client)
@@ -58,22 +64,24 @@ Successfully tested with **Angular 8**, **Angular 7**, and its Router, PathLocat
5864

5965
## Sample-Auth-Server
6066

61-
You can use the OIDC-Sample-Server mentioned in the samples for Testing. It assumes, that your Web-App runs on http://localhost:8080.
67+
You can use the OIDC-Sample-Server mentioned in the samples for Testing. It assumes, that your Web-App runs on http://localhost:8080
6268

6369
Username/Password: max/geheim
6470

65-
*clientIds:*
71+
*clientIds:*
72+
6673
- spa-demo (implicit flow)
6774
- demo-resource-owner (resource owner password flow)
6875

6976
*redirectUris:*
77+
7078
- localhost:[8080-8089|4200-4202]
7179
- localhost:[8080-8089|4200-4202]/index.html
7280
- localhost:[8080-8089|4200-4202]/silent-refresh.html
7381

7482
## Installing
7583

76-
```
84+
```sh
7785
npm i angular-oauth2-oidc --save
7886
```
7987

@@ -85,7 +93,7 @@ import { OAuthModule } from 'angular-oauth2-oidc';
8593
// etc.
8694

8795
@NgModule({
88-
imports: [
96+
imports: [
8997
// etc.
9098
HttpClientModule,
9199
OAuthModule.forRoot()
@@ -96,12 +104,12 @@ import { OAuthModule } from 'angular-oauth2-oidc';
96104
// etc.
97105
],
98106
bootstrap: [
99-
AppComponent
107+
AppComponent
100108
]
101109
})
102110
export class AppModule {
103111
}
104-
```
112+
```
105113

106114
## Configuring for Implicit Flow
107115

@@ -116,7 +124,6 @@ Hence, the original API is still supported.
116124
import { AuthConfig } from 'angular-oauth2-oidc';
117125

118126
export const authConfig: AuthConfig = {
119-
120127
// Url of the Identity Provider
121128
issuer: 'https://steyer-identity-server.azurewebsites.net/identity',
122129

@@ -215,9 +222,47 @@ The following snippet contains the template for the login page:
215222

216223
### Skipping the Login Form
217224

218-
If you don't want to display a login form that tells the user that they are redirected to the identity server, you can use the convenience function ``this.oauthService.loadDiscoveryDocumentAndLogin();`` instead of ``this.oauthService.loadDiscoveryDocumentAndTryLogin();`` when setting up the library.
225+
If you don't want to display a login form that tells the user that they are redirected to the identity server, you can use the convenience function ``this.oauthService.loadDiscoveryDocumentAndLogin();`` instead of ``this.oauthService.loadDiscoveryDocumentAndTryLogin();`` when setting up the library.
226+
227+
This directly redirects the user to the identity server if there are no valid tokens. Ensure you have your `issuer` set to your discovery document endpoint!
219228

220-
This directly redirects the user to the identity server if there are no valid tokens.
229+
230+
#### Manually skipping
231+
232+
This is sort of what ``this.oauthService.loadDiscoveryDocumentAndLogin();`` is doing under the hood. But this gives you a fair bit more control
233+
234+
```TypeScript
235+
this.oauthService
236+
.loadDiscoveryDocumentAndTryLogin(/* { your LoginOptions }*/) // checks to see if the current url contains id token and access token
237+
.(hasReceivedTokens => {
238+
// this would have stored all the tokens needed
239+
if (hasReceivedTokens) {
240+
// carry on with your app
241+
return Promise.resolve();
242+
243+
/* if you wish to do something when the user receives tokens from the identity server,
244+
* use the event stream or the `onTokenReceived` callback in LoginOptions.
245+
*
246+
* this.oauthService.events(filter(e => e.type === 'token_received')).subscribe()
247+
*/
248+
} else {
249+
// may want to check if you were previously authenticated
250+
if (this.oauthService.hasValidAccessToken() && this.oauthService.hasValidIdToken()) {
251+
return Promise.resolve();
252+
} else {
253+
// to safe guard this from progressing through the calling promise,
254+
// resolve it when it directed to the sign up page
255+
return new Promise(resolve => {
256+
this.oauthService.initLoginFlow();
257+
// example if you are using explicit flow
258+
this.window.addEventListener('unload', () => {
259+
resolve(true);
260+
});
261+
});
262+
}
263+
}
264+
})
265+
```
221266

222267

223268
### Calling a Web API with an Access Token
@@ -253,16 +298,9 @@ See the [documentation](https://manfredsteyer.github.io/angular-oauth2-oidc/docs
253298

254299
## Tutorials
255300

256-
* [Tutorial with Demo Servers available online](https://www.softwarearchitekt.at/post/2016/07/03/authentication-in-angular-2-with-oauth2-oidc-and-guards-for-the-newest-new-router-english-version.aspx)
257-
* [Angular Authentication with OpenID Connect and Okta in 20 Minutes](https://developer.okta.com/blog/2017/04/17/angular-authentication-with-oidc)
258-
* [Add Authentication to Your Angular PWA](https://developer.okta.com/blog/2017/06/13/add-authentication-angular-pwa)
259-
* [Build an Ionic App with User Authentication](https://developer.okta.com/blog/2017/08/22/build-an-ionic-app-with-user-authentication)
260-
* [On-Site Workshops](https://www.softwarearchitekt.at)
261-
262-
263-
264-
265-
266-
267-
268-
301+
- [Tutorial with Demo Servers available online](https://www.softwarearchitekt.at/post/2016/07/03/authentication-in-angular-2-with-oauth2-oidc-and-guards-for-the-newest-new-router-english-version.aspx)
302+
- [Angular Authentication with OpenID Connect and Okta in 20 Minutes](https://developer.okta.com/blog/2017/04/17/angular-authentication-with-oidc)
303+
- [Add Authentication to Your Angular PWA](https://developer.okta.com/blog/2017/06/13/add-authentication-angular-pwa)
304+
- [Build an Ionic App with User Authentication](https://developer.okta.com/blog/2017/08/22/build-an-ionic-app-with-user-authentication)
305+
- [On-Site Workshops](https://www.softwarearchitekt.at)
306+
- [Angular 6 with Auth0 using this library](https://github.com/jeroenheijmans/sample-auth0-angular-oauth2-oidc)

angular.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
},
1818
"configurations": {
1919
"production": {
20-
"project": "projects/lib/ng-package.prod.json"
20+
"project": "projects/lib/ng-package.prod.json",
21+
"tsConfig": "projects/lib/tsconfig.lib.prod.json"
2122
}
2223
}
2324
},
@@ -45,6 +46,7 @@
4546
"build": {
4647
"builder": "@angular-devkit/build-angular:browser",
4748
"options": {
49+
"aot": true,
4850
"outputPath": "dist/sample",
4951
"index": "projects/sample/src/index.html",
5052
"main": "projects/sample/src/main.ts",
@@ -63,6 +65,12 @@
6365
},
6466
"configurations": {
6567
"production": {
68+
"budgets": [
69+
{
70+
"type": "anyComponentStyle",
71+
"maximumWarning": "6kb"
72+
}
73+
],
6674
"fileReplacements": [
6775
{
6876
"replace": "projects/sample/src/environments/environment.ts",
@@ -285,5 +293,8 @@
285293
"@schematics/angular:component": {
286294
"styleext": "css"
287295
}
296+
},
297+
"cli": {
298+
"analytics": false
288299
}
289300
}

docs-src/silent-refresh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ This file is loaded into the hidden iframe after getting new tokens. Its only ta
6666
<html>
6767
<body>
6868
<script>
69-
parent.postMessage(location.hash, location.origin);
69+
window.parent.postMessage(location.hash || ('#' + location.search), location.origin);
7070
</script>
7171
</body>
7272
</html>

docs/classes/AuthConfig.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,12 @@ <h3 id="inputs">
449449
</span>
450450
</td>
451451
</tr>
452+
<tr>
453+
<td class="col-md-4">
454+
<i>Type : </i> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/number" target="_blank" >number</a></code>
455+
456+
</td>
457+
</tr>
452458
<tr>
453459
<td class="col-md-4">
454460
<div class="io-line">Defined in <a href="" data-line="222" class="link-to-prism">projects/lib/src/auth.config.ts:222</a></div>
@@ -2206,7 +2212,7 @@ <h3 id="inputs">
22062212
/**
22072213
* The window of time (in seconds) to allow the current time to deviate when validating id_token&#x27;s iat and exp values.
22082214
*/
2209-
public clockSkewInSec?: 600;
2215+
public clockSkewInSec?: number;
22102216

22112217
/**
22122218
* The interceptors waits this time span if there is no token

0 commit comments

Comments
 (0)