From 2362f047044bb30a8a42115f564910461938599e Mon Sep 17 00:00:00 2001 From: Bastian Wagner Date: Thu, 12 Sep 2024 09:50:57 +0200 Subject: [PATCH] URL angepasst --- idp/src/application/application.controller.ts | 2 +- idp/src/idp/auth/auth.controller.ts | 4 +- idp/src/shared/users.service.ts | 2 + idp_client/src/app/app.routes.ts | 1 + .../src/app/auth/login/login.component.ts | 4 +- .../app/auth/register/register.component.ts | 4 +- .../app/auth/reset-pw/reset-pw.component.ts | 4 +- .../src/app/core/guards/session-key.guard.ts | 2 +- .../components/help/help.component.html | 92 +++++++++++++++++++ .../components/help/help.component.scss | 7 ++ .../components/help/help.component.spec.ts | 23 +++++ .../components/help/help.component.ts | 14 +++ .../app/dashboard/dashboard.component.html | 5 +- .../app/dashboard/dashboard.component.scss | 2 +- .../src/app/dashboard/dashboard.component.ts | 6 +- idp_client/src/assets/icons/question.svg | 1 + idp_client/src/styles.scss | 4 + 17 files changed, 164 insertions(+), 13 deletions(-) create mode 100644 idp_client/src/app/dashboard/components/help/help.component.html create mode 100644 idp_client/src/app/dashboard/components/help/help.component.scss create mode 100644 idp_client/src/app/dashboard/components/help/help.component.spec.ts create mode 100644 idp_client/src/app/dashboard/components/help/help.component.ts create mode 100644 idp_client/src/assets/icons/question.svg diff --git a/idp/src/application/application.controller.ts b/idp/src/application/application.controller.ts index b48cc39..433e464 100644 --- a/idp/src/application/application.controller.ts +++ b/idp/src/application/application.controller.ts @@ -12,7 +12,7 @@ export class ApplicationController { return { success: true }; } - @Post('login') + @Post('authorize') loginUser(@Body() b: LoginUserDto): Promise { return this.userService.loginUser({ username: b.username, diff --git a/idp/src/idp/auth/auth.controller.ts b/idp/src/idp/auth/auth.controller.ts index 462eea1..df5ce49 100644 --- a/idp/src/idp/auth/auth.controller.ts +++ b/idp/src/idp/auth/auth.controller.ts @@ -7,7 +7,7 @@ import { Client } from 'src/model'; import { UsersService } from 'src/shared/users.service'; import { CustomLogger } from 'src/shared/logger/custom.logger'; -@Controller('auth') +@Controller('') export class AuthController { constructor( private usersService: UsersService, @@ -72,7 +72,7 @@ export class AuthController { ); } - @Post('token') + @Post('authorize') @FormDataRequest() async getToken( @Body('client_id') clientId: string, diff --git a/idp/src/shared/users.service.ts b/idp/src/shared/users.service.ts index 8cc1b14..632ae92 100644 --- a/idp/src/shared/users.service.ts +++ b/idp/src/shared/users.service.ts @@ -126,6 +126,7 @@ export class UsersService { if (getUserAccessToken) { user.accessToken = this.createAccessToken(user); user.refreshToken = this.createRefreshToken(user); + console.log(this.jwtService.verify(user.accessToken)) return user; } @@ -237,6 +238,7 @@ export class UsersService { try { const decoded = this.jwtService.verify(token); this.activityRepo.logAccessTokenVerification(); + console.log(decoded) return decoded; } catch (e) { this.logger.error(`Token ${token} is invalid. Error: ${e.message}`); diff --git a/idp_client/src/app/app.routes.ts b/idp_client/src/app/app.routes.ts index 3160a6b..e39ee89 100644 --- a/idp_client/src/app/app.routes.ts +++ b/idp_client/src/app/app.routes.ts @@ -7,6 +7,7 @@ import { ResetPwComponent } from './auth/reset-pw/reset-pw.component'; export const routes: Routes = [ { path: 'login', component: LoginComponent, canActivate: [SessionKeyGuard] }, + { path: 'authorize', component: LoginComponent, canActivate: [SessionKeyGuard] }, { path: 'register', component: RegisterComponent }, { path: 'pw-reset', component: ResetPwComponent }, { path: 'dashboard', component: DashboardComponent, canActivate: [SessionKeyGuard] }, diff --git a/idp_client/src/app/auth/login/login.component.ts b/idp_client/src/app/auth/login/login.component.ts index 85fb53d..b191dc5 100644 --- a/idp_client/src/app/auth/login/login.component.ts +++ b/idp_client/src/app/auth/login/login.component.ts @@ -67,7 +67,7 @@ export class LoginComponent { if (!this.client_id) { return; } - this.http.get('api/auth/', { + this.http.get('api/', { params }).subscribe({ next: (client) => { @@ -82,7 +82,7 @@ export class LoginComponent { login() { this.isLoading = true; - const url = this.client_id ? `api/auth/login?client_id=${this.client_id}` : 'api/app/login'; + const url = this.client_id ? `api/authorize?client_id=${this.client_id}` : 'api/app/authorize'; console.log(url, this.client_id) this.http.post(url, this.loginForm.value). pipe( diff --git a/idp_client/src/app/auth/register/register.component.ts b/idp_client/src/app/auth/register/register.component.ts index af3a3a2..6fa38b8 100644 --- a/idp_client/src/app/auth/register/register.component.ts +++ b/idp_client/src/app/auth/register/register.component.ts @@ -39,7 +39,7 @@ export class RegisterComponent { const params = (this.route.snapshot.queryParamMap as any)["params"]; this.redirectUri = params.redirect_uri; this.client_id = params.client_id; - this.http.get('api/auth/', { + this.http.get('', { params }).subscribe({ next: (client) => { @@ -57,7 +57,7 @@ export class RegisterComponent { this.toast.error('Passwords do not match'); return; } - this.http.post('api/auth/register?'+ 'client_id=' + this.client_id, this.registerForm.value).pipe( + this.http.post('api/register?'+ 'client_id=' + this.client_id, this.registerForm.value).pipe( this.toast.observe({ loading: 'Registering...', success: 'Registration successfull, please log in', diff --git a/idp_client/src/app/auth/reset-pw/reset-pw.component.ts b/idp_client/src/app/auth/reset-pw/reset-pw.component.ts index 03d4a68..93dc5de 100644 --- a/idp_client/src/app/auth/reset-pw/reset-pw.component.ts +++ b/idp_client/src/app/auth/reset-pw/reset-pw.component.ts @@ -38,7 +38,7 @@ export class ResetPwComponent { resetPassword() { - this.http.post('api/auth/reset', this.resetPw.value) + this.http.post('api/reset', this.resetPw.value) .pipe( this.toast.observe({ loading: 'Sende Mail...', @@ -59,7 +59,7 @@ export class ResetPwComponent { this.toast.error('Die Passwörter stimmen nicht überein'); return; } - this.http.post('api/auth/reset', this.setNewPwForm.value) + this.http.post('api/reset', this.setNewPwForm.value) .pipe( this.toast.observe({ loading: 'Setze neues Passwort', diff --git a/idp_client/src/app/core/guards/session-key.guard.ts b/idp_client/src/app/core/guards/session-key.guard.ts index 7b626ee..438df44 100644 --- a/idp_client/src/app/core/guards/session-key.guard.ts +++ b/idp_client/src/app/core/guards/session-key.guard.ts @@ -40,7 +40,7 @@ export class SessionKeyGuard { const id = window.localStorage.getItem("auth_session_key"); if (!id ||id.length < 2) { return resolve(true); } - const url = this.client_id ? 'api/auth/login-with-session-id' : 'api/auth/login-with-session-id/userlogin' + const url = this.client_id ? 'api/login-with-session-id' : 'api/login-with-session-id/userlogin' this.http.post(url, { code: id, diff --git a/idp_client/src/app/dashboard/components/help/help.component.html b/idp_client/src/app/dashboard/components/help/help.component.html new file mode 100644 index 0000000..60c3265 --- /dev/null +++ b/idp_client/src/app/dashboard/components/help/help.component.html @@ -0,0 +1,92 @@ +
Hilfe
+ +
+

Authentifizierung:

+
Für den Login:
+ https://sso.beantastic.de/authorize + +
Query:
+ + + + + + + + + + + + + + + + + + +
response_typecode
client_id<CLIENT ID>
redirect_uri<REDIRECT URI>
scope<SCOPE>
+ +
+
+ Danach wird der user mit einem auth code als parameter ?code=<AUTH_CODE> zurückgeleitet. +
+

Code => Accesstoken:

+
den Code tauscht der Client gegen den Accesstoken:
+ POST: https://sso.beantastic.de/api/authorize +
Body (Form):
+ + + + + + + + + + + + + + + + + +
client_id<CLIENT ID>
client_secret<Secret>
code<Auth Code>
grant_typeauthorization code
+ +

Accesstoken prüfen:

+
Einen Accesstoken verifizieren:
+ POST: https://sso.beantastic.de/api/verify +
Body (Form):
+ + + + + +
access_token<Access Token>
+
Return:
+ Decoded Token + +

neuen Accesstoken:

+
um einen Refreshtoken in einen Accesstoken zu tauschen:
+ POST: https://sso.beantastic.de/api/authorize +
Body (Form):
+ + + + + + + + + + + + + +
client_id<CLIENT_ID>
code<Refresh Token>
grant_typerefreshtoken
+
+
+ + + + \ No newline at end of file diff --git a/idp_client/src/app/dashboard/components/help/help.component.scss b/idp_client/src/app/dashboard/components/help/help.component.scss new file mode 100644 index 0000000..ad28475 --- /dev/null +++ b/idp_client/src/app/dashboard/components/help/help.component.scss @@ -0,0 +1,7 @@ +h1, h2, h3, h4, h5 { + margin-bottom: 0; +} + +h5 { + margin-top: 8px; +} \ No newline at end of file diff --git a/idp_client/src/app/dashboard/components/help/help.component.spec.ts b/idp_client/src/app/dashboard/components/help/help.component.spec.ts new file mode 100644 index 0000000..1a1e963 --- /dev/null +++ b/idp_client/src/app/dashboard/components/help/help.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { HelpComponent } from './help.component'; + +describe('HelpComponent', () => { + let component: HelpComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [HelpComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(HelpComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/idp_client/src/app/dashboard/components/help/help.component.ts b/idp_client/src/app/dashboard/components/help/help.component.ts new file mode 100644 index 0000000..20676a2 --- /dev/null +++ b/idp_client/src/app/dashboard/components/help/help.component.ts @@ -0,0 +1,14 @@ +import { Component } from '@angular/core'; +import { MatButtonModule } from '@angular/material/button'; +import { MatDialogModule } from '@angular/material/dialog'; + +@Component({ + selector: 'app-help', + standalone: true, + imports: [MatDialogModule, MatButtonModule], + templateUrl: './help.component.html', + styleUrl: './help.component.scss' +}) +export class HelpComponent { + +} diff --git a/idp_client/src/app/dashboard/dashboard.component.html b/idp_client/src/app/dashboard/dashboard.component.html index 25bbaf2..79a096d 100644 --- a/idp_client/src/app/dashboard/dashboard.component.html +++ b/idp_client/src/app/dashboard/dashboard.component.html @@ -1,8 +1,11 @@
SSO Beantastic
+
+
{{ userName }}
-
+ +
diff --git a/idp_client/src/app/dashboard/dashboard.component.scss b/idp_client/src/app/dashboard/dashboard.component.scss index 0729e6c..98f2f59 100644 --- a/idp_client/src/app/dashboard/dashboard.component.scss +++ b/idp_client/src/app/dashboard/dashboard.component.scss @@ -63,7 +63,7 @@ justify-content: center; } -.logout{ +.logout, .question { width: 32px; height: 32px; cursor: pointer; diff --git a/idp_client/src/app/dashboard/dashboard.component.ts b/idp_client/src/app/dashboard/dashboard.component.ts index f97f47e..6096e43 100644 --- a/idp_client/src/app/dashboard/dashboard.component.ts +++ b/idp_client/src/app/dashboard/dashboard.component.ts @@ -11,6 +11,7 @@ import { CreateClientComponent } from './components/create-client/create-client. import { CreateHotToastRef, HotToastService } from '@ngxpert/hot-toast'; import {MatBottomSheet, MatBottomSheetModule, MatBottomSheetRef} from '@angular/material/bottom-sheet'; import { LoginChartComponent } from './components/charts/login/login.chart.component'; +import { HelpComponent } from './components/help/help.component'; @Component({ selector: 'app-dashboard', @@ -38,7 +39,6 @@ export class DashboardComponent implements OnInit { this.router.navigateByUrl("/login"); return; } - this.load(); } @@ -123,6 +123,10 @@ export class DashboardComponent implements OnInit { logout() { this.userService.logout(); } + + openHelp() { + this.dialog.open(HelpComponent) + } } diff --git a/idp_client/src/assets/icons/question.svg b/idp_client/src/assets/icons/question.svg new file mode 100644 index 0000000..6182877 --- /dev/null +++ b/idp_client/src/assets/icons/question.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/idp_client/src/styles.scss b/idp_client/src/styles.scss index 3b861d8..34f9fa3 100644 --- a/idp_client/src/styles.scss +++ b/idp_client/src/styles.scss @@ -20,6 +20,10 @@ html, body { background-image: url("assets/icons/logout.svg"); } +.question { + background-image: url("assets/icons/question.svg"); +} + .flex-row{ display: flex; flex-direction: row;