You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With regards to tree shaking, beginning with version 9, the ``JwksValidationHandler`` has been moved to a library of its own. If you need it for implementing **implicit flow**, please install it using npm:
22
+
23
+
```
24
+
npm i angular-oauth2-oidc-jwks --save
25
+
```
26
+
27
+
After that, you can import it into your application by using this:
Please note, that this dependency is not needed for the **code flow**, which is nowadays the **recommended** flow for single page applications. This also results in smaller bundle sizes.
40
+
41
+
20
42
## Tested Environment
21
43
22
44
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).
@@ -36,12 +58,12 @@ Successfully tested with **Angular 9** and its Router, PathLocationStrategy as w
36
58
- We plan one major release for each Angular version
37
59
- Will contain new features
38
60
- Will contain bug fixes and PRs
39
-
- Critical Bugfixes on demand
61
+
- Critical bugfixes on demand
40
62
41
63
## Contributions
42
64
43
65
- Feel free to file pull requests
44
-
- The closed issues contain some ideas for PRs and enhancements (see labels)
66
+
- The issues contain some ideas for PRs and enhancements (see labels)
45
67
- 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:
46
68
47
69
```sh
@@ -51,8 +73,9 @@ Successfully tested with **Angular 9** and its Router, PathLocationStrategy as w
51
73
52
74
## Features
53
75
76
+
- Logging in via Code Flow + PKCE
77
+
- Hence, you are safe for the upcoming OAuth 2.1
54
78
- Logging in via Implicit Flow (where a user is redirected to Identity Provider)
55
-
- Logging in via Code Flow + PKCE
56
79
- "Logging in" via Password Flow (where a user enters their password into the client)
57
80
- Token Refresh for all supported flows
58
81
- Automatically refreshing a token when/some time before it expires
@@ -64,20 +87,23 @@ Successfully tested with **Angular 9** and its Router, PathLocationStrategy as w
64
87
65
88
## Sample-Auth-Server
66
89
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
90
+
You can use the OIDC-Sample-Server used in our examples. It assumes, that your Web-App runs on http://localhost:4200
This section shows how to implement login leveraging implicit flow. This is the OAuth2/OIDC flow best suitable for
117
-
Single Page Application. It sends the user to the Identity Provider's login page. After logging in, the SPA gets tokens.
118
-
This also allows for single sign on as well as single sign off.
140
+
# Logging in
119
141
120
-
To configure the library, the following sample uses the new configuration API introduced with Version 2.1.
121
-
Hence, the original API is still supported.
142
+
Since Version 8, this library supports code flow and [PKCE](https://tools.ietf.org/html/rfc7636) to align with the current draft of the [OAuth 2.0 Security Best Current Practice](https://tools.ietf.org/html/draft-ietf-oauth-security-topics-13) document. This is also the foundation of the upcoming OAuth 2.1.
The following snippet contains the template for the login page:
202
-
203
-
```HTML
204
-
<h1*ngIf="!name">
205
-
Hallo
206
-
</h1>
207
-
<h1*ngIf="name">
208
-
Hallo, {{name}}
209
-
</h1>
210
-
211
-
<buttonclass="btn btn-default"(click)="login()">
212
-
Login
213
-
</button>
214
-
<buttonclass="btn btn-default"(click)="logoff()">
215
-
Logout
216
-
</button>
217
-
218
-
<div>
219
-
Username/Passwort zum Testen: max/geheim
220
-
</div>
221
-
```
222
201
223
202
### Skipping the Login Form
224
203
@@ -227,44 +206,6 @@ If you don't want to display a login form that tells the user that they are redi
227
206
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!
228
207
229
208
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
-
returnPromise.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.
// may want to check if you were previously authenticated
250
-
if (this.oauthService.hasValidAccessToken() &&this.oauthService.hasValidIdToken()) {
251
-
returnPromise.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
-
returnnewPromise(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
-
```
266
-
267
-
268
209
### Calling a Web API with an Access Token
269
210
270
211
You can automate this task by switching ``sendAccessToken`` on and by setting ``allowedUrls`` to an array with prefixes for the respective URLs. Use lower case for the prefixes.
@@ -280,10 +221,6 @@ OAuthModule.forRoot({
280
221
281
222
If you need more versatility, you can look in the [documentation](https://manfredsteyer.github.io/angular-oauth2-oidc/docs/additional-documentation/working-with-httpinterceptors.html) how to setup a custom interceptor.
282
223
283
-
## Code Flow + PKCE
284
-
285
-
See docs: https://manfredsteyer.github.io/angular-oauth2-oidc/docs/additional-documentation/code-flow-+-pcke.html
286
-
287
224
## Token Refresh
288
225
289
226
See docs: https://manfredsteyer.github.io/angular-oauth2-oidc/docs/additional-documentation/refreshing-a-token.html
@@ -292,6 +229,10 @@ See docs: https://manfredsteyer.github.io/angular-oauth2-oidc/docs/additional-do
292
229
293
230
If you use the ``PathLocationStrategy`` (which is on by default) and have a general catch-all-route (``path: '**'``) you should be fine. Otherwise look up the section ``Routing with the HashStrategy`` in the [documentation](https://manfredsteyer.github.io/angular-oauth2-oidc/docs/).
294
231
232
+
## Implicit Flow
233
+
234
+
Nowadays, using code flow + PKCE -- as shown above -- is the recommended OAuth 2/OIDC flow for SPAs. To use the older implicit flow, lookup this docs: https://manfredsteyer.github.io/angular-oauth2-oidc/docs/additional-documentation/implicit-flow.html
235
+
295
236
## More Documentation (!)
296
237
297
238
See the [documentation](https://manfredsteyer.github.io/angular-oauth2-oidc/docs/) for more information about this library.
Copy file name to clipboardExpand all lines: docs-src/implicit-flow-config-discovery.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
# Original Config API
2
2
3
+
> This describes the older config API which is nowadays only supported for the sake of backwards compatibility.
4
+
3
5
To configure the library you just have to set some properties on startup. For this, the following sample uses the constructor of the AppComponent which is called before routing kicks in.
4
6
5
7
Please note that the following sample uses the original config API. For information about the new config API have a look to the project's README above.
0 commit comments