URL angepasst

This commit is contained in:
Bastian Wagner
2024-09-12 09:50:57 +02:00
parent 2359c9c5e9
commit 2362f04704
17 changed files with 164 additions and 13 deletions

View File

@@ -12,7 +12,7 @@ export class ApplicationController {
return { success: true };
}
@Post('login')
@Post('authorize')
loginUser(@Body() b: LoginUserDto): Promise<User> {
return this.userService.loginUser({
username: b.username,

View File

@@ -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,

View File

@@ -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}`);

View File

@@ -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] },

View File

@@ -67,7 +67,7 @@ export class LoginComponent {
if (!this.client_id) { return; }
this.http.get<any>('api/auth/', {
this.http.get<any>('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(

View File

@@ -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<any>('api/auth/', {
this.http.get<any>('', {
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',

View File

@@ -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',

View File

@@ -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,

View File

@@ -0,0 +1,92 @@
<div mat-dialog-title>Hilfe</div>
<mat-dialog-content>
<div class="mat-body">
<h3>Authentifizierung:</h3>
<div>Für den Login:</div>
<code>https://sso.beantastic.de/authorize</code>
<h5>Query:</h5>
<table>
<tr>
<td>response_type</td>
<td>code</td>
</tr>
<tr>
<td>client_id</td>
<td>&lt;CLIENT ID&gt;</td>
</tr>
<tr>
<td>redirect_uri</td>
<td>&lt;REDIRECT URI&gt;</td>
</tr>
<tr>
<td>scope</td>
<td>&lt;SCOPE&gt;</td>
</tr>
</table>
<br />
<div>
Danach wird der user mit einem auth code als parameter <code>?code=<b>&lt;AUTH_CODE&gt;</b></code> zurückgeleitet.
</div>
<h3>Code => Accesstoken:</h3>
<div>den Code tauscht der Client gegen den Accesstoken:</div>
<code>POST: https://sso.beantastic.de/api/authorize</code>
<h5>Body (Form):</h5>
<table>
<tr>
<td>client_id</td>
<td>&lt;CLIENT ID&gt;</td>
</tr>
<tr>
<td>client_secret</td>
<td>&lt;Secret&gt;</td>
</tr>
<tr>
<td>code</td>
<td>&lt;Auth Code&gt;</td>
</tr>
<tr>
<td>grant_type</td>
<td>authorization code</td>
</tr>
</table>
<h3>Accesstoken prüfen:</h3>
<div>Einen Accesstoken verifizieren:</div>
<code>POST: https://sso.beantastic.de/api/verify</code>
<h5>Body (Form):</h5>
<table>
<tr>
<td>access_token</td>
<td>&lt;Access Token&gt;</td>
</tr>
</table>
<h5>Return:</h5>
Decoded Token
<h3>neuen Accesstoken:</h3>
<div>um einen Refreshtoken in einen Accesstoken zu tauschen:</div>
<code>POST: https://sso.beantastic.de/api/authorize</code>
<h5>Body (Form):</h5>
<table>
<tr>
<td>client_id</td>
<td>&lt;CLIENT_ID&gt;</td>
</tr>
<tr>
<td>code</td>
<td>&lt;Refresh Token&gt;</td>
</tr>
<tr>
<td>grant_type</td>
<td>refreshtoken</td>
</tr>
</table>
</div>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button mat-dialog-close >Schließen</button>
</mat-dialog-actions>

View File

@@ -0,0 +1,7 @@
h1, h2, h3, h4, h5 {
margin-bottom: 0;
}
h5 {
margin-top: 8px;
}

View File

@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HelpComponent } from './help.component';
describe('HelpComponent', () => {
let component: HelpComponent;
let fixture: ComponentFixture<HelpComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [HelpComponent]
})
.compileComponents();
fixture = TestBed.createComponent(HelpComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -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 {
}

View File

@@ -1,7 +1,10 @@
<div class="header">
<div class="title">SSO Beantastic</div>
<div class="flex-row">
<div class="question" (click)="openHelp()"></div>
<div> {{ userName }}</div>
<div class="logout" (click)="logout()" ></div>
</div>

View File

@@ -63,7 +63,7 @@
justify-content: center;
}
.logout{
.logout, .question {
width: 32px;
height: 32px;
cursor: pointer;

View File

@@ -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();
}
@@ -124,6 +124,10 @@ export class DashboardComponent implements OnInit {
this.userService.logout();
}
openHelp() {
this.dialog.open(HelpComponent)
}
}

View File

@@ -0,0 +1 @@
<svg enable-background="new 0 0 512 512" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><g id="_x32_9_question"><g><path d="m72.632 129.761h178.052c2.702 0 4.888-2.186 4.888-4.888s-2.186-4.888-4.888-4.888h-178.052c-2.702 0-4.888 2.186-4.888 4.888s2.186 4.888 4.888 4.888z"/><path d="m72.632 177.873h108.583c2.702 0 4.888-2.186 4.888-4.888s-2.186-4.888-4.888-4.888h-108.583c-2.702 0-4.888 2.186-4.888 4.888s2.186 4.888 4.888 4.888z"/><path d="m72.632 225.984h217.16c2.702 0 4.888-2.186 4.888-4.888s-2.186-4.888-4.888-4.888h-217.16c-2.702 0-4.888 2.186-4.888 4.888-.001 2.702 2.186 4.888 4.888 4.888z"/><path d="m72.632 274.091h217.16c2.702 0 4.888-2.186 4.888-4.888s-2.186-4.888-4.888-4.888h-217.16c-2.702 0-4.888 2.186-4.888 4.888s2.186 4.888 4.888 4.888z"/><path d="m210.034 312.425h-137.402c-2.702 0-4.888 2.186-4.888 4.888s2.186 4.888 4.888 4.888h137.403c2.702 0 4.888-2.186 4.888-4.888s-2.187-4.888-4.889-4.888z"/><path d="m210.034 360.532h-137.402c-2.702 0-4.888 2.186-4.888 4.888s2.186 4.888 4.888 4.888h137.403c2.702 0 4.888-2.186 4.888-4.888s-2.187-4.888-4.889-4.888z"/><path d="m379.756 269.501v-165.91c0-1.047-.532-2.599-1.461-3.509l-92.685-90.829c-.881-.863-2.384-1.389-3.461-1.389h-216.754c-20.165 0-36.568 16.403-36.568 36.568v379.788c0 20.165 16.403 36.568 36.568 36.568h208.864c21.614 26.436 54.462 43.347 91.195 43.347 64.911 0 117.72-52.828 117.72-117.768 0-60.092-45.232-109.779-103.418-116.866zm-92.68-245.078 75.799 74.26h-66.562c-5.094 0-9.238-4.168-9.238-9.29v-64.97zm-221.681 426.589c-14.77 0-26.791-12.021-26.791-26.791v-379.789c0-14.77 12.021-26.791 26.791-26.791h211.904v71.752c0 10.512 8.531 19.067 19.014 19.067h73.666v160.256c-1.504-.057-3.008-.115-4.526-.115-64.939 0-117.768 52.828-117.768 117.768 0 23.861 7.153 46.073 19.397 64.643zm300.059 43.347c-59.545 0-107.991-48.446-107.991-107.991s48.446-107.991 107.991-107.991c59.521 0 107.943 48.446 107.943 107.991s-48.422 107.991-107.943 107.991z"/><path d="m367.354 319.553h-3.848c-19.707 0-35.737 16.036-35.737 35.742 0 2.702 2.186 4.888 4.888 4.888s4.888-2.186 4.888-4.888c0-14.317 11.644-25.965 25.961-25.965h3.848c14.317 0 25.965 11.648 25.965 25.965 0 28.204-25.253 36.571-26.419 37.571-8.24 4.187-13.362 12.522-13.362 21.764v11.534c0 2.702 2.186 4.888 4.888 4.888s4.888-2.186 4.888-4.888v-11.534c0-5.538 3.07-10.536 8.011-13.047 1.123-.978 31.77-11.54 31.77-46.288.001-19.707-16.035-35.742-35.741-35.742z"/><path d="m358.36 440.514c-2.702 0-4.888 2.186-4.888 4.888v2.893c0 2.702 2.186 4.888 4.888 4.888s4.888-2.186 4.888-4.888v-2.893c0-2.702-2.186-4.888-4.888-4.888z"/></g></g><g id="Layer_1"/></svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@@ -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;