Skip to content

Commit c60ffec

Browse files
Merge pull request #755 from linjie997/master
Update sample app and silent-refresh.html script
2 parents 41a6ea0 + 795baec commit c60ffec

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

docs-src/implicit-flow.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ This file is loaded into the hidden iframe after getting new tokens. Its only ta
154154
<html>
155155
<body>
156156
<script>
157-
window.parent.postMessage(location.hash || ('#' + location.search), location.origin);
157+
(window.opener || window.parent).postMessage(location.hash || ('#' + location.search), location.origin);
158158
</script>
159159
</body>
160160
</html>
@@ -190,4 +190,4 @@ To automatically refresh a token when/ some time before it expires, just call th
190190
this.oauthService.setupAutomaticSilentRefresh();
191191
```
192192

193-
By default, this event is fired after 75% of the token's life time is over. You can adjust this factor by setting the property ``timeoutFactor`` to a value between 0 and 1. For instance, 0.5 means, that the event is fired after half of the life time is over and 0.33 triggers the event after a third.
193+
By default, this event is fired after 75% of the token's life time is over. You can adjust this factor by setting the property ``timeoutFactor`` to a value between 0 and 1. For instance, 0.5 means, that the event is fired after half of the life time is over and 0.33 triggers the event after a third.

projects/sample/src/app/auth-code-flow.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export const authCodeFlowConfig: AuthConfig = {
99
? '/#/index.html'
1010
: '/index.html'),
1111

12+
silentRefreshRedirectUri: `${window.location.origin}/silent-refresh.html`,
13+
1214
// The SPA's id. The SPA is registerd with this id at the auth-server
1315
// clientId: 'server.code',
1416
clientId: 'spa',

projects/sample/src/app/home/home.component.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ <h2>Login with Implicit Flow</h2>
2828
</div>
2929
</div>
3030

31+
<div class="panel panel-default">
32+
<div class="panel-body">
33+
<h2>Login with Implicit Flow in popup</h2>
34+
<p>
35+
<button class="btn btn-default" (click)="loginImplicitInPopup()">Login</button>
36+
<button class="btn btn-default" (click)="logout()">Logout</button>
37+
</p>
38+
<b>Username/Password:</b> max/geheim
39+
</div>
40+
</div>
41+
3142
<div class="panel panel-default">
3243
<div class="panel-body">
3344
<h2>Login with Code Flow</h2>
@@ -39,6 +50,17 @@ <h2>Login with Code Flow</h2>
3950
</div>
4051
</div>
4152

53+
<div class="panel panel-default">
54+
<div class="panel-body">
55+
<h2>Login with Code Flow in popup</h2>
56+
<p>
57+
<button class="btn btn-default" (click)="loginCodeInPopup()">Login</button>
58+
<button class="btn btn-default" (click)="logout()">Logout</button>
59+
</p>
60+
<b>Username/Password:</b> alice/alice
61+
</div>
62+
</div>
63+
4264
<div class="panel panel-default">
4365
<div class="panel-body">
4466
<p>

projects/sample/src/app/home/home.component.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ export class HomeComponent implements OnInit {
3434
// the parameter here is optional. It's passed around and can be used after logging in
3535
}
3636

37+
async loginImplicitInPopup() {
38+
39+
// Tweak config for implicit flow
40+
this.oauthService.configure(authConfig);
41+
await this.oauthService.loadDiscoveryDocument();
42+
sessionStorage.setItem('flow', 'implicit');
43+
44+
this.oauthService.initLoginFlowInPopup().then(() => {
45+
this.loadUserProfile();
46+
});
47+
// the parameter here is optional. It's passed around and can be used after logging in
48+
}
49+
3750
async loginCode() {
3851
// Tweak config for code flow
3952
this.oauthService.configure(authCodeFlowConfig);
@@ -44,6 +57,17 @@ export class HomeComponent implements OnInit {
4457
// the parameter here is optional. It's passed around and can be used after logging in
4558
}
4659

60+
async loginCodeInPopup() {
61+
// Tweak config for code flow
62+
this.oauthService.configure(authCodeFlowConfig);
63+
await this.oauthService.loadDiscoveryDocument();
64+
sessionStorage.setItem('flow', 'code');
65+
66+
this.oauthService.initLoginFlowInPopup().then(() => {
67+
this.loadUserProfile();
68+
});
69+
}
70+
4771
logout() {
4872
this.oauthService.logOut();
4973
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<html>
22
<body>
33
<script>
4-
parent.postMessage(location.hash, location.origin);
4+
(window.opener || window.parent).postMessage(location.hash || ('#' + location.search), location.origin);
55
</script>
66
</body>
7-
</html>
7+
</html>

0 commit comments

Comments
 (0)