Skip to content

Commit 795baec

Browse files
committed
Sample: add login in popup for both implicit flow and codeflow
1 parent 6f0c4fa commit 795baec

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

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
}

0 commit comments

Comments
 (0)