Skip to content

Commit e409e60

Browse files
committed
IOT-43: Login using KOMBIT adgangsstyring
1 parent 8e540ce commit e409e60

File tree

7 files changed

+33
-15
lines changed

7 files changed

+33
-15
lines changed

src/app/applications/applications.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { IotDevicesModule } from './iot-devices/iot-devices.module';
1515
import { SharedModule } from '@shared/shared.module';
1616
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
1717
import { DirectivesModule } from '@shared/directives/directives.module';
18-
import { HttpClientModule } from '@angular/common/http';
1918
import { NGMaterialModule } from '@shared/Modules/materiale.module';
2019
import { BulkImportComponent } from './bulk-import/bulk-import.component';
2120
import { DeleteDialogComponent } from '@shared/components/delete-dialog/delete-dialog.component';
@@ -44,7 +43,6 @@ import { DeleteDialogComponent } from '@shared/components/delete-dialog/delete-d
4443
IotDevicesModule,
4544
DatatargetModule,
4645
DirectivesModule,
47-
HttpClientModule,
4846
FormModule,
4947
SharedModule,
5048
FontAwesomeModule,

src/app/auth/auth.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
<button class="btn btn-primary" type="submit" [disabled]="!authForm.valid">{{'Login'}}</button>
2626
</div>
2727
</form>
28+
<a class="btn btn-secondary mt-4" href="{{getKombitLoginUrl()}}">{{'AUTH.KOMBIT-BUTTON' | translate}}</a>
2829
</div>
2930
</div>

src/app/auth/auth.component.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { NgForm } from '@angular/forms';
33
import { AuthService } from './auth.service';
44
import { Router } from '@angular/router';
55
import { TranslateService } from '@ngx-translate/core';
6+
import { environment } from '@environments/environment';
67

78
@Component({
89
selector: 'app-auth',
@@ -21,9 +22,15 @@ export class AuthComponent implements OnInit {
2122
constructor(
2223
private authService: AuthService,
2324
private router: Router,
24-
public translate: TranslateService,) { }
25+
public translate: TranslateService
26+
) {}
2527

26-
ngOnInit(): void { }
28+
ngOnInit(): void {}
29+
30+
getKombitLoginUrl() {
31+
const frontpage = encodeURI(window.location.origin + '/dashboard');
32+
return `${environment.baseUrl}auth/kombit/login?redirect=${frontpage}`;
33+
}
2734

2835
onSwitchMode() {
2936
this.isLoginMode = !this.isLoginMode;

src/app/auth/auth.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class AuthService {
4949
return this.restService.get('auth/me');
5050
}
5151

52-
private setSession(jwt: string) {
52+
setSession(jwt: string) {
5353
localStorage.setItem('id_token', jwt);
5454
}
5555

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { ActivatedRoute, Router } from '@angular/router';
3+
import { AuthService } from '@auth/auth.service';
24

35
@Component({
46
selector: 'app-dashboard',
57
templateUrl: './dashboard.component.html',
6-
styleUrls: ['./dashboard.component.scss']
8+
styleUrls: ['./dashboard.component.scss'],
79
})
810
export class DashboardComponent implements OnInit {
9-
10-
constructor() { }
11-
12-
ngOnInit(): void {
11+
constructor(
12+
private route: ActivatedRoute,
13+
private authService: AuthService,
14+
private router: Router
15+
) {
16+
this.route.queryParams.subscribe((params) => {
17+
const jwt = params['jwt'];
18+
if (jwt) {
19+
this.authService.setSession(jwt);
20+
// Clear the URL from the parameter
21+
this.router.navigate(['/dashboard']);
22+
}
23+
});
1324
}
1425

26+
ngOnInit(): void {}
1527
}

src/app/shared/helpers/auth-jwt.interceptor.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import {
44
HttpRequest,
55
HttpHandler,
66
HttpInterceptor,
7-
HttpErrorResponse,
87
} from '@angular/common/http';
9-
import { Observable, throwError } from 'rxjs';
10-
import { retry, catchError } from 'rxjs/operators';
11-
import { environment } from '../../../environments/environment.prod';
8+
import { Observable } from 'rxjs';
9+
import { environment } from '../../../environments/environment';
1210

1311
@Injectable()
1412
export class AuthJwtInterceptor implements HttpInterceptor {
@@ -18,6 +16,7 @@ export class AuthJwtInterceptor implements HttpInterceptor {
1816
): Observable<HttpEvent<any>> {
1917
// If we're not calling the baseurl skip this. Is there a better way?
2018
if (req.url.indexOf(environment.baseUrl) != 0) {
19+
console.warn("Skip adding Bearer since we're not calling baseUrl ...");
2120
return next.handle(req);
2221
}
2322

src/assets/i18n/da.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,8 @@
639639
},
640640
"AUTH": {
641641
"EMAIL": "Email",
642-
"PASSWORD": "Adgangskode"
642+
"PASSWORD": "Adgangskode",
643+
"KOMBIT-BUTTON": "Login med KOMBIT Adgangsstyring"
643644
},
644645
"DASHBOARD": {
645646
"WELCOME": "Velkommen til OS2IoT",

0 commit comments

Comments
 (0)