Skip to content

Update sample app and silent-refresh.html script #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>