@@ -9,40 +9,41 @@ import { Logger, LoggerInterface } from '../decorators/Logger';
9
9
@Service ( )
10
10
export class AuthService {
11
11
12
- constructor (
13
- @Logger ( __filename ) private log : LoggerInterface ,
14
- @OrmRepository ( ) private userRepository : UserRepository
15
- ) { }
16
-
17
- public parseBasicAuthFromRequest ( req : express . Request ) : { username : string , password : string } {
18
- const authorization = req . header ( 'authorization' ) ;
19
-
20
- if ( authorization && authorization . split ( ' ' ) [ 0 ] === 'Basic' ) {
21
- this . log . info ( 'Credentials provided by the client' ) ;
22
- const decodedBase64 = Buffer . from ( authorization . split ( ' ' ) [ 1 ] , 'base64' ) . toString ( 'ascii' ) ;
23
- const username = decodedBase64 . split ( ':' ) [ 0 ] ;
24
- const password = decodedBase64 . split ( ':' ) [ 1 ] ;
25
- if ( username && password ) {
26
- return { username, password } ;
27
- }
28
- }
29
-
30
- this . log . info ( 'No credentials provided by the client' ) ;
31
- return undefined ;
12
+ constructor (
13
+ @Logger ( __filename ) private log : LoggerInterface ,
14
+ @OrmRepository ( ) private userRepository : UserRepository ,
15
+ ) {
16
+ }
17
+
18
+ public parseBasicAuthFromRequest ( req : express . Request ) : { username : string , password : string } {
19
+ const authorization = req . header ( 'authorization' ) ;
20
+
21
+ if ( authorization && authorization . split ( ' ' ) [ 0 ] === 'Basic' ) {
22
+ this . log . info ( 'Credentials provided by the client' ) ;
23
+ const decodedBase64 = Buffer . from ( authorization . split ( ' ' ) [ 1 ] , 'base64' ) . toString ( 'ascii' ) ;
24
+ const username = decodedBase64 . split ( ':' ) [ 0 ] ;
25
+ const password = decodedBase64 . split ( ':' ) [ 1 ] ;
26
+ if ( username && password ) {
27
+ return { username, password } ;
28
+ }
32
29
}
33
30
34
- public async validateUser ( username : string , password : string ) : Promise < User > {
35
- const user = await this . userRepository . findOne ( {
36
- where : {
37
- username,
38
- } ,
39
- } ) ;
31
+ this . log . info ( 'No credentials provided by the client' ) ;
32
+ return undefined ;
33
+ }
40
34
41
- if ( await User . comparePassword ( user , password ) ) {
42
- return user ;
43
- }
35
+ public async validateUser ( username : string , password : string ) : Promise < User > {
36
+ const user = await this . userRepository . findOne ( {
37
+ where : {
38
+ username,
39
+ } ,
40
+ } ) ;
44
41
45
- return undefined ;
42
+ if ( await User . comparePassword ( user , password ) ) {
43
+ return user ;
46
44
}
47
45
46
+ return undefined ;
47
+ }
48
+
48
49
}
0 commit comments