logging & feedback
This commit is contained in:
@@ -124,6 +124,9 @@ export class UsersService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (client.clientSecret !== clientSecret) {
|
if (client.clientSecret !== clientSecret) {
|
||||||
|
this.logger.error(
|
||||||
|
`Client ${clientId} provided invalid secret ${clientSecret}`,
|
||||||
|
);
|
||||||
throw new HttpException('Invalid client', 401);
|
throw new HttpException('Invalid client', 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,21 +135,27 @@ export class UsersService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (grantType !== 'authorization_code') {
|
if (grantType !== 'authorization_code') {
|
||||||
|
this.logger.error(
|
||||||
|
`Client ${clientId} provided invalid grant type ${grantType}`,
|
||||||
|
);
|
||||||
throw new HttpException('Invalid grant type', 401);
|
throw new HttpException('Invalid grant type', 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = await this.tokenRepo.findByCode(code);
|
const token = await this.tokenRepo.findByCode(code);
|
||||||
if (!token) {
|
if (!token) {
|
||||||
|
this.logger.error(`Token ${code} not found`);
|
||||||
throw new HttpException('Invalid token', 401);
|
throw new HttpException('Invalid token', 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token.client.id !== clientId) {
|
if (token.client.id !== clientId) {
|
||||||
|
this.logger.error(`Token ${code} not found for client ${clientId}`);
|
||||||
throw new HttpException('Invalid token', 401);
|
throw new HttpException('Invalid token', 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await this.userRepo.findById(token.user.id);
|
const user = await this.userRepo.findById(token.user.id);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
|
this.logger.error(`User ${token.user.id} of token not found`);
|
||||||
throw new HttpException('Invalid token', 401);
|
throw new HttpException('Invalid token', 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,10 +194,12 @@ export class UsersService {
|
|||||||
async getNewAccessToken(refreshToken: string) {
|
async getNewAccessToken(refreshToken: string) {
|
||||||
const payload = this.jwtService.verify(refreshToken);
|
const payload = this.jwtService.verify(refreshToken);
|
||||||
if (payload.type !== 'refresh') {
|
if (payload.type !== 'refresh') {
|
||||||
|
this.logger.error(`Token ${refreshToken} is not a refresh token`);
|
||||||
throw new HttpException('Invalid token', 401);
|
throw new HttpException('Invalid token', 401);
|
||||||
}
|
}
|
||||||
const user = await this.userRepo.findById(payload.id);
|
const user = await this.userRepo.findById(payload.id);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
|
this.logger.error(`User ${payload.id} not found for refresh token`);
|
||||||
throw new HttpException('Invalid token', 401);
|
throw new HttpException('Invalid token', 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,6 +217,7 @@ export class UsersService {
|
|||||||
const decoded = this.jwtService.verify(token);
|
const decoded = this.jwtService.verify(token);
|
||||||
return decoded;
|
return decoded;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
this.logger.error(`Token ${token} is invalid. Error: ${e.message}`);
|
||||||
throw new HttpException(e.message, 401);
|
throw new HttpException(e.message, 401);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,9 @@
|
|||||||
},
|
},
|
||||||
"serve": {
|
"serve": {
|
||||||
"builder": "@angular-devkit/build-angular:dev-server",
|
"builder": "@angular-devkit/build-angular:dev-server",
|
||||||
|
"options": {
|
||||||
|
"proxyConfig": "proxy.conf.json"
|
||||||
|
},
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"production": {
|
"production": {
|
||||||
"buildTarget": "idp_client:build:production"
|
"buildTarget": "idp_client:build:production"
|
||||||
|
|||||||
11
idp_client/proxy.conf.json
Normal file
11
idp_client/proxy.conf.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"/api": {
|
||||||
|
"target": "http://localhost:5000",
|
||||||
|
"secure": false,
|
||||||
|
"logLevel": "debug",
|
||||||
|
"changeOrigin": true,
|
||||||
|
"pathRewrite": {
|
||||||
|
"^/api": "/api"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
<i class="login__icon fas fa-lock safe"></i>
|
<i class="login__icon fas fa-lock safe"></i>
|
||||||
<input type="password" formControlName="password" class="login__input" placeholder="Password">
|
<input type="password" formControlName="password" class="login__input" placeholder="Password">
|
||||||
</div>
|
</div>
|
||||||
<button class="button login__submit" (click)="login()" [disabled]="!client_id || loginForm.invalid">
|
<button class="button login__submit" (click)="login()" [disabled]="!client_id || loginForm.invalid || isLoading">
|
||||||
<span class="button__text">Log In Now</span>
|
<span class="button__text">Log In Now</span>
|
||||||
<i class="button__icon fas fa-chevron-right"></i>
|
<i class="button__icon fas fa-chevron-right"></i>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { Component, inject } from '@angular/core';
|
|||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||||
import { environment } from '../../../environments/environment';
|
|
||||||
import { HotToastService } from '@ngxpert/hot-toast';
|
import { HotToastService } from '@ngxpert/hot-toast';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -23,6 +22,8 @@ export class LoginComponent {
|
|||||||
client: string = "";
|
client: string = "";
|
||||||
client_id = null;
|
client_id = null;
|
||||||
|
|
||||||
|
isLoading = false;
|
||||||
|
|
||||||
loginForm = new FormGroup({
|
loginForm = new FormGroup({
|
||||||
username: new FormControl(''),
|
username: new FormControl(''),
|
||||||
password: new FormControl(''),
|
password: new FormControl(''),
|
||||||
@@ -37,7 +38,7 @@ export class LoginComponent {
|
|||||||
const id = window.localStorage.getItem("auth_sesion_key");
|
const id = window.localStorage.getItem("auth_sesion_key");
|
||||||
if (!id ||id.length < 2) { return; }
|
if (!id ||id.length < 2) { return; }
|
||||||
|
|
||||||
this.http.post(environment.api_url + 'auth/login-with-session-id', {
|
this.http.post('api/auth/login-with-session-id', {
|
||||||
code: id,
|
code: id,
|
||||||
client_id: this.client_id
|
client_id: this.client_id
|
||||||
}).pipe(
|
}).pipe(
|
||||||
@@ -64,7 +65,7 @@ export class LoginComponent {
|
|||||||
this.redirectUri = params.redirect_uri;
|
this.redirectUri = params.redirect_uri;
|
||||||
this.client_id = params.client_id;
|
this.client_id = params.client_id;
|
||||||
|
|
||||||
this.http.get<any>(environment.api_url + 'auth/', {
|
this.http.get<any>('api/auth/', {
|
||||||
params
|
params
|
||||||
}).subscribe({
|
}).subscribe({
|
||||||
next: (client) => {
|
next: (client) => {
|
||||||
@@ -78,8 +79,16 @@ export class LoginComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
login() {
|
login() {
|
||||||
this.toast.loading('Logging in...');
|
this.isLoading = true;
|
||||||
this.http.post(environment.api_url + 'auth/login?'+ 'client_id=' + this.client_id, this.loginForm.value).subscribe({
|
this.http.post('api/auth/login?'+ 'client_id=' + this.client_id, this.loginForm.value).
|
||||||
|
pipe(
|
||||||
|
this.toast.observe({
|
||||||
|
loading: 'Logging in...',
|
||||||
|
success: 'Login successfull',
|
||||||
|
error: 'Invalid login'
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.subscribe({
|
||||||
next: (data) => {
|
next: (data) => {
|
||||||
if (data["code"] != null) {
|
if (data["code"] != null) {
|
||||||
window.localStorage.setItem("auth_sesion_key", data["session_key"]);
|
window.localStorage.setItem("auth_sesion_key", data["session_key"]);
|
||||||
@@ -88,7 +97,7 @@ export class LoginComponent {
|
|||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
this.toast.error('Invalid login');
|
this.isLoading = false;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { Component, inject } from '@angular/core';
|
|||||||
import { FormGroup, FormControl, Validators, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
import { FormGroup, FormControl, Validators, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { HotToastService } from '@ngxpert/hot-toast';
|
import { HotToastService } from '@ngxpert/hot-toast';
|
||||||
import { environment } from '../../../environments/environment';
|
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -40,7 +39,7 @@ export class RegisterComponent {
|
|||||||
const params = (this.route.snapshot.queryParamMap as any)["params"];
|
const params = (this.route.snapshot.queryParamMap as any)["params"];
|
||||||
this.redirectUri = params.redirect_uri;
|
this.redirectUri = params.redirect_uri;
|
||||||
this.client_id = params.client_id;
|
this.client_id = params.client_id;
|
||||||
this.http.get<any>(environment.api_url + 'auth/', {
|
this.http.get<any>('api/auth/', {
|
||||||
params
|
params
|
||||||
}).subscribe({
|
}).subscribe({
|
||||||
next: (client) => {
|
next: (client) => {
|
||||||
@@ -58,10 +57,10 @@ export class RegisterComponent {
|
|||||||
this.toast.error('Passwords do not match');
|
this.toast.error('Passwords do not match');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.http.post(environment.api_url + 'auth/register?'+ 'client_id=' + this.client_id, this.registerForm.value).pipe(
|
this.http.post('api/auth/register?'+ 'client_id=' + this.client_id, this.registerForm.value).pipe(
|
||||||
this.toast.observe({
|
this.toast.observe({
|
||||||
loading: 'Registering...',
|
loading: 'Registering...',
|
||||||
success: 'Registration successfull'
|
success: 'Registration successfull, please log in',
|
||||||
})
|
})
|
||||||
).subscribe({
|
).subscribe({
|
||||||
next: () => {
|
next: () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user