Skip to content

Commit 89913ff

Browse files
Merge pull request #1422 from damienbod/fabiangosebrink/Adding-abstract-services
Fabiangosebrink/adding abstract services
2 parents ad4b090 + 83151f3 commit 89913ff

29 files changed

+1756
-1818
lines changed

docs/site/angular-auth-oidc-client/docs/documentation/public-api.md renamed to docs/site/angular-auth-oidc-client/docs/documentation/01-public-api.md

Lines changed: 692 additions & 692 deletions
Large diffs are not rendered by default.

docs/site/angular-auth-oidc-client/docs/documentation/configuration.md renamed to docs/site/angular-auth-oidc-client/docs/documentation/02-configuration.md

Lines changed: 469 additions & 476 deletions
Large diffs are not rendered by default.

docs/site/angular-auth-oidc-client/docs/documentation/login-logout.md renamed to docs/site/angular-auth-oidc-client/docs/documentation/03-login-logout.md

Lines changed: 206 additions & 206 deletions
Large diffs are not rendered by default.

docs/site/angular-auth-oidc-client/docs/documentation/deploy-to-different-domains.md renamed to docs/site/angular-auth-oidc-client/docs/documentation/04-deploy-to-different-domains.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
---
2-
sidebar_label: Deploying to different domains
3-
sidebar_position: 5
4-
---
5-
6-
# Deploying to different domains
7-
8-
If the client and the Secure Token Service provider are hosted on 2 different domains, the `X-Frame-Options` HTTPS header needs to be set to allow all iframes. Once set, use the CSP HTTPS header to only allow the required domains.
9-
**The silent renew requires this.**
10-
11-
Add this header to responses from the server that serves your SPA:
12-
13-
```bash
14-
Content-Security-Policy: script-src 'self' 'unsafe-inline';style-src 'self' 'unsafe-inline';img-src 'self' data:;font-src 'self';frame-ancestors 'self' https://localhost:44318;block-all-mixed-content
15-
```
16-
17-
where `https://localhost:44318` is the address of your secure token secure server, i.e. the authority which issues tokens.
18-
19-
E.g. if you use nginx to serve your Angular application, you can configure the server as follows:
20-
21-
```javascript
22-
http {
23-
server {
24-
...
25-
add_header Content-Security-Policy "script-src 'self' 'unsafe-inline';style-src 'self' 'unsafe-inline';img-src 'self' data:;font-src 'self';frame-ancestors 'self' https://localhost:44318;block-all-mixed-content";
26-
```
1+
---
2+
sidebar_label: Deploying to different domains
3+
sidebar_position: 4
4+
---
5+
6+
# Deploying to different domains
7+
8+
If the client and the Secure Token Service provider are hosted on 2 different domains, the `X-Frame-Options` HTTPS header needs to be set to allow all iframes. Once set, use the CSP HTTPS header to only allow the required domains.
9+
**The silent renew requires this.**
10+
11+
Add this header to responses from the server that serves your SPA:
12+
13+
```bash
14+
Content-Security-Policy: script-src 'self' 'unsafe-inline';style-src 'self' 'unsafe-inline';img-src 'self' data:;font-src 'self';frame-ancestors 'self' https://localhost:44318;block-all-mixed-content
15+
```
16+
17+
where `https://localhost:44318` is the address of your secure token secure server, i.e. the authority which issues tokens.
18+
19+
E.g. if you use nginx to serve your Angular application, you can configure the server as follows:
20+
21+
```javascript
22+
http {
23+
server {
24+
...
25+
add_header Content-Security-Policy "script-src 'self' 'unsafe-inline';style-src 'self' 'unsafe-inline';img-src 'self' data:;font-src 'self';frame-ancestors 'self' https://localhost:44318;block-all-mixed-content";
26+
```

docs/site/angular-auth-oidc-client/docs/documentation/public-events.md renamed to docs/site/angular-auth-oidc-client/docs/documentation/05-public-events.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
sidebar_label: Public Events
3-
sidebar_position: 6
3+
sidebar_position: 5
44
---
55

66
# Public Events
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
sidebar_label: Custom Logger
3+
sidebar_position: 6
4+
---
5+
6+
# Custom Logger
7+
8+
```ts
9+
import { AbstractLoggerService } from 'angular-auth-oidc-client';
10+
11+
@Injectable()
12+
export class MyLoggerService implements AbstractLoggerService {
13+
// ...
14+
}
15+
```
16+
17+
Then provide the class in the module:
18+
19+
```ts
20+
@NgModule({
21+
imports: [
22+
AuthModule.forRoot({
23+
config: {
24+
// ...
25+
},
26+
}),
27+
],
28+
providers: [{ provide: AbstractLoggerService, useClass: MyLoggerService }],
29+
exports: [AuthModule],
30+
})
31+
export class AuthConfigModule {}
32+
```

docs/site/angular-auth-oidc-client/docs/documentation/custom-storage.md renamed to docs/site/angular-auth-oidc-client/docs/documentation/07-custom-storage.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The following example shows a custom storage that uses `localStorage`:
1313
import { AbstractSecurityStorage } from 'angular-auth-oidc-client';
1414

1515
@Injectable()
16-
export class CustomStorage implements AbstractSecurityStorage {
16+
export class MyStorageService implements AbstractSecurityStorage {
1717
read(key: string) {
1818
return localStorage.getItem(key);
1919
}
@@ -37,9 +37,14 @@ Then provide the class in the module:
3737
```ts
3838
@NgModule({
3939
imports: [
40-
// ...
41-
AuthModule.forRoot({ config: { storage: new CustomStorage() } })
40+
AuthModule.forRoot({
41+
config: {
42+
// ...
43+
},
44+
}),
4245
],
43-
// ...
46+
providers: [{ provide: AbstractSecurityStorage, useClass: MyStorageService }],
47+
exports: [AuthModule],
4448
})
49+
export class AuthConfigModule {}
4550
```

docs/site/angular-auth-oidc-client/docs/documentation/guards.md renamed to docs/site/angular-auth-oidc-client/docs/documentation/08-guards.md

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
1-
---
2-
sidebar_label: Using Route Guards
3-
sidebar_position: 7
4-
---
5-
6-
# Using Route Guards
7-
8-
> Guards should only be applied to protected URLs. There should be no guard active on the default route where the authorization request is processed.
9-
10-
Please refer to the auto-login guard in this repo as a reference. It is important that the callback logic can be run on a route without the guard running or run before the guard logic.
11-
12-
```ts
13-
import { Injectable } from '@angular/core';
14-
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
15-
import { OidcSecurityService } from 'angular-auth-oidc-client';
16-
import { Observable } from 'rxjs';
17-
import { map } from 'rxjs/operators';
18-
19-
@Injectable({ providedIn: 'root' })
20-
export class AuthorizationGuard implements CanActivate {
21-
constructor(private oidcSecurityService: OidcSecurityService, private router: Router) {}
22-
23-
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> {
24-
return this.oidcSecurityService.isAuthenticated$.pipe(
25-
map(({ isAuthenticated }) => {
26-
// allow navigation if authenticated
27-
if (isAuthenticated) {
28-
return true;
29-
}
30-
31-
// redirect if not authenticated
32-
return this.router.parseUrl('/unauthorized');
33-
})
34-
);
35-
}
36-
}
37-
```
38-
39-
To apply the guard for specific routes you have to add it to the route configuration e.g. with `canActivate`:
40-
41-
```ts
42-
const appRoutes: Routes = [
43-
{
44-
path: 'protected',
45-
component: <yourComponent>,
46-
canActivate: [AuthorizationGuard]
47-
},
48-
// ...
49-
];
50-
```
51-
52-
All other guard types like `canLoad` or `canActivateChild` work in a similar way. However, the guard class has to implement the respective interfaces and methods accordingly.
1+
---
2+
sidebar_label: Using Route Guards
3+
sidebar_position: 8
4+
---
5+
6+
# Using Route Guards
7+
8+
> Guards should only be applied to protected URLs. There should be no guard active on the default route where the authorization request is processed.
9+
10+
Please refer to the auto-login guard in this repo as a reference. It is important that the callback logic can be run on a route without the guard running or run before the guard logic.
11+
12+
```ts
13+
import { Injectable } from '@angular/core';
14+
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
15+
import { OidcSecurityService } from 'angular-auth-oidc-client';
16+
import { Observable } from 'rxjs';
17+
import { map } from 'rxjs/operators';
18+
19+
@Injectable({ providedIn: 'root' })
20+
export class AuthorizationGuard implements CanActivate {
21+
constructor(private oidcSecurityService: OidcSecurityService, private router: Router) {}
22+
23+
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> {
24+
return this.oidcSecurityService.isAuthenticated$.pipe(
25+
map(({ isAuthenticated }) => {
26+
// allow navigation if authenticated
27+
if (isAuthenticated) {
28+
return true;
29+
}
30+
31+
// redirect if not authenticated
32+
return this.router.parseUrl('/unauthorized');
33+
})
34+
);
35+
}
36+
}
37+
```
38+
39+
To apply the guard for specific routes you have to add it to the route configuration e.g. with `canActivate`:
40+
41+
```ts
42+
const appRoutes: Routes = [
43+
{
44+
path: 'protected',
45+
component: <yourComponent>,
46+
canActivate: [AuthorizationGuard]
47+
},
48+
// ...
49+
];
50+
```
51+
52+
All other guard types like `canLoad` or `canActivateChild` work in a similar way. However, the guard class has to implement the respective interfaces and methods accordingly.

docs/site/angular-auth-oidc-client/docs/documentation/auto-login.md renamed to docs/site/angular-auth-oidc-client/docs/documentation/09-auto-login.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
sidebar_label: Auto Login
3-
sidebar_position: 8
3+
sidebar_position: 9
44
---
55

66
# Auto Login

0 commit comments

Comments
 (0)