Skip to content

Commit 62b36aa

Browse files
authored
Merge pull request #119 from sourcefuse/GH-118
feat(arc-saas): integrate keycloak login
2 parents bed6c9c + 503af4e commit 62b36aa

File tree

4 files changed

+64
-21
lines changed

4 files changed

+64
-21
lines changed

projects/arc-lib/src/lib/core/auth/auth.service.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { HttpHeaders } from '@angular/common/http';
2-
import { Inject, Injectable } from '@angular/core';
3-
import { Router } from '@angular/router';
4-
import { APP_CONFIG } from '@project-lib/app-config';
1+
import {HttpHeaders} from '@angular/common/http';
2+
import {Inject, Injectable} from '@angular/core';
3+
import {Router} from '@angular/router';
4+
import {APP_CONFIG} from '@project-lib/app-config';
55

66
import {
77
CoreAuthModule,
@@ -18,20 +18,20 @@ import {
1818
GetTokenCommand,
1919
GetCurrentUserCommand,
2020
} from '@project-lib/core/auth';
21-
import { SignUpAdapter } from '@project-lib/core/auth/adapters/signup-adapter.service';
22-
import { CreateExternalUserCommand } from '@project-lib/core/auth/commands/create-external-user.command';
23-
import { CreateTokenCommand } from '@project-lib/core/auth/commands/create-token.command';
21+
import {SignUpAdapter} from '@project-lib/core/auth/adapters/signup-adapter.service';
22+
import {CreateExternalUserCommand} from '@project-lib/core/auth/commands/create-external-user.command';
23+
import {CreateTokenCommand} from '@project-lib/core/auth/commands/create-token.command';
2424
import {
2525
AuthTokenSkipHeader,
2626
ErrToastSkipHeader,
2727
} from '@project-lib/core/constants';
28-
import { IAnyObject } from '@project-lib/core/i-any-object';
28+
import {IAnyObject} from '@project-lib/core/i-any-object';
2929
import {
3030
AnyAdapter,
3131
ApiService,
3232
UserSessionStoreService,
3333
} from '@project-lib/core/index';
34-
import { NgxPermissionsService } from 'ngx-permissions';
34+
import {NgxPermissionsService} from 'ngx-permissions';
3535
import {
3636
Observable,
3737
switchMap,
@@ -66,7 +66,7 @@ export class AuthService {
6666
private readonly anyAdapter: AnyAdapter,
6767
private readonly permissionsService: NgxPermissionsService,
6868
@Inject(APP_CONFIG) private readonly appConfig: IAnyObject,
69-
) { }
69+
) {}
7070

7171
public isLoggedIn(): Observable<boolean> {
7272
return this.currentUser().pipe(
@@ -342,8 +342,26 @@ export class AuthService {
342342
}),
343343
);
344344
}
345+
loginViaKeycloak(): void {
346+
const form = document.createElement('form');
347+
form.method = 'POST';
348+
form.action = `${this.appConfig.baseApiUrl}${this.appConfig.authServiceUrl}/auth/keycloak`;
349+
form.style.display = 'none';
345350

351+
const clientId = document.createElement('input');
352+
clientId.type = 'hidden';
353+
clientId.name = 'client_id';
354+
clientId.value = this.appConfig.clientId;
355+
form.appendChild(clientId);
346356

357+
const clientSecret = document.createElement('input');
358+
clientSecret.type = 'hidden';
359+
clientSecret.name = 'client_secret';
360+
clientSecret.value = this.appConfig.publicKey;
361+
form.appendChild(clientSecret);
362+
document.body.appendChild(form);
363+
form.submit();
364+
}
347365
loginViaCognito(): void {
348366
const form = document.createElement('form');
349367
form.method = 'POST';
@@ -380,7 +398,7 @@ export class AuthService {
380398
const clientSecret = document.createElement('input');
381399
clientSecret.type = 'hidden';
382400
clientSecret.name = 'logout_uri';
383-
clientSecret.value = this.appConfig.publicKey;;
401+
clientSecret.value = this.appConfig.publicKey;
384402
form.appendChild(clientSecret);
385403
document.body.appendChild(form);
386404
form.submit();

projects/saas-ui/src/app/shared/auth/login/login.component.html

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,27 @@ <h2 class="head-wrapper">Multi Tenancy SaaS Application</h2>
1414

1515
<!-- Social login button -->
1616
<div class="btn">
17-
<button
18-
class="btn-wrapper"
19-
nbButton
20-
size="medium"
21-
shape="round"
22-
(click)="loginViaCognito()"
23-
>
24-
Sign In with Amazon Cognito
25-
</button>
17+
<div class="idp-wrapper">
18+
<button
19+
class="btn-wrapper"
20+
nbButton
21+
size="medium"
22+
shape="round"
23+
(click)="loginViaCognito()"
24+
>
25+
Sign In with Amazon Cognito
26+
</button>
27+
<button
28+
class="btn-wrapper"
29+
nbButton
30+
size="medium"
31+
shape="round"
32+
(click)="loginViaKeycloak()"
33+
>
34+
Sign In with Keycloak
35+
</button>
36+
</div>
37+
2638
<p>OR</p>
2739
<button
2840
nbButton
@@ -31,7 +43,7 @@ <h2 class="head-wrapper">Multi Tenancy SaaS Application</h2>
3143
shape="round"
3244
(click)="withoutLogin()"
3345
>
34-
Registration
46+
Sign Up
3547
</button>
3648
</div>
3749
</div>

projects/saas-ui/src/app/shared/auth/login/login.component.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@
5555
width: 25px;
5656
}
5757
.btn{
58+
.idp-wrapper {
59+
display: inline-grid;
60+
grid-gap: 15px;
61+
62+
@media (max-width: 575px) {
63+
display: flex;
64+
flex-direction: column;
65+
align-items: center;
66+
}
67+
}
5868
.btn-wrapper{
5969
color: #ffffff !important;
6070
background: #f00a18 !important;

projects/saas-ui/src/app/shared/auth/login/login.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export class LoginComponent extends RouteComponentBaseDirective {
6363
this.authService.loginViaCognito();
6464
}
6565

66+
loginViaKeycloak() {
67+
this.authService.loginViaKeycloak();
68+
}
6669
withoutLogin() {
6770
this.router.navigate(['/tenant/add-lead']);
6871
}

0 commit comments

Comments
 (0)