Skip to content

Commit

Permalink
Merge pull request #755 from linjie997/master
Browse files Browse the repository at this point in the history
Update sample app and silent-refresh.html script
  • Loading branch information
manfredsteyer authored Mar 21, 2020
2 parents 41a6ea0 + 795baec commit c60ffec
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs-src/implicit-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ This file is loaded into the hidden iframe after getting new tokens. Its only ta
<html>
<body>
<script>
window.parent.postMessage(location.hash || ('#' + location.search), location.origin);
(window.opener || window.parent).postMessage(location.hash || ('#' + location.search), location.origin);
</script>
</body>
</html>
Expand Down Expand Up @@ -190,4 +190,4 @@ To automatically refresh a token when/ some time before it expires, just call th
this.oauthService.setupAutomaticSilentRefresh();
```

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.
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.
2 changes: 2 additions & 0 deletions projects/sample/src/app/auth-code-flow.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const authCodeFlowConfig: AuthConfig = {
? '/#/index.html'
: '/index.html'),

silentRefreshRedirectUri: `${window.location.origin}/silent-refresh.html`,

// The SPA's id. The SPA is registerd with this id at the auth-server
// clientId: 'server.code',
clientId: 'spa',
Expand Down
22 changes: 22 additions & 0 deletions projects/sample/src/app/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ <h2>Login with Implicit Flow</h2>
</div>
</div>

<div class="panel panel-default">
<div class="panel-body">
<h2>Login with Implicit Flow in popup</h2>
<p>
<button class="btn btn-default" (click)="loginImplicitInPopup()">Login</button>
<button class="btn btn-default" (click)="logout()">Logout</button>
</p>
<b>Username/Password:</b> max/geheim
</div>
</div>

<div class="panel panel-default">
<div class="panel-body">
<h2>Login with Code Flow</h2>
Expand All @@ -39,6 +50,17 @@ <h2>Login with Code Flow</h2>
</div>
</div>

<div class="panel panel-default">
<div class="panel-body">
<h2>Login with Code Flow in popup</h2>
<p>
<button class="btn btn-default" (click)="loginCodeInPopup()">Login</button>
<button class="btn btn-default" (click)="logout()">Logout</button>
</p>
<b>Username/Password:</b> alice/alice
</div>
</div>

<div class="panel panel-default">
<div class="panel-body">
<p>
Expand Down
24 changes: 24 additions & 0 deletions projects/sample/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ export class HomeComponent implements OnInit {
// the parameter here is optional. It's passed around and can be used after logging in
}

async loginImplicitInPopup() {

// Tweak config for implicit flow
this.oauthService.configure(authConfig);
await this.oauthService.loadDiscoveryDocument();
sessionStorage.setItem('flow', 'implicit');

this.oauthService.initLoginFlowInPopup().then(() => {
this.loadUserProfile();
});
// the parameter here is optional. It's passed around and can be used after logging in
}

async loginCode() {
// Tweak config for code flow
this.oauthService.configure(authCodeFlowConfig);
Expand All @@ -44,6 +57,17 @@ export class HomeComponent implements OnInit {
// the parameter here is optional. It's passed around and can be used after logging in
}

async loginCodeInPopup() {
// Tweak config for code flow
this.oauthService.configure(authCodeFlowConfig);
await this.oauthService.loadDiscoveryDocument();
sessionStorage.setItem('flow', 'code');

this.oauthService.initLoginFlowInPopup().then(() => {
this.loadUserProfile();
});
}

logout() {
this.oauthService.logOut();
}
Expand Down
4 changes: 2 additions & 2 deletions projects/sample/src/silent-refresh.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>
<body>
<script>
parent.postMessage(location.hash, location.origin);
(window.opener || window.parent).postMessage(location.hash || ('#' + location.search), location.origin);
</script>
</body>
</html>
</html>

0 comments on commit c60ffec

Please sign in to comment.