1+ import { ConfigService } from '@nestjs/config' ;
12import { HttpService } from '@nestjs/axios' ;
23import {
34 Logger ,
@@ -12,21 +13,20 @@ import { HttpsProxyAgent } from 'https-proxy-agent';
1213export class AuthenticationService {
1314 private readonly logger = new Logger ( AuthenticationService . name ) ;
1415
15- constructor ( private readonly httpService : HttpService ) { }
16+ constructor (
17+ private readonly httpService : HttpService ,
18+ private readonly configService : ConfigService ,
19+ ) { }
1620
1721 loginAuthorize ( state : string , nonce : string ) {
18- this . logger . log (
19- "envoi du lien d'authorization {/authentication/login_authorize} route" ,
20- ) ;
21- return `${ process . env . AGENTCONNECT_URL } /api/v2/authorize?response_type=code&acr_values=eidas1&scope=${ process . env . AGENTCONNECT_SCOPE } &client_id=${ process . env . AGENTCONNECT_CLIENTID } &redirect_uri=${ process . env . AGENTCONNECT_REDIRECT_URL } /login_callback&state=${ state } &nonce=${ nonce } ` ;
22+ return `${ this . configService . get ( 'AGENTCONNECT_URL' ) } /api/v2/authorize?response_type=code&acr_values=eidas1&scope=${ this . configService . get ( 'AGENTCONNECT_SCOPE' ) } &client_id=${ this . configService . get ( 'AGENTCONNECT_CLIENTID' ) } &redirect_uri=${ this . configService . get ( 'AGENTCONNECT_REDIRECT_URL' ) } /login_callback&state=${ state } &nonce=${ nonce } ` ;
2223 }
2324
2425 async loginCallback ( code : string , state : string , sendedState : string ) {
25- this . logger . log ( '{/authentication/login_callback} route' ) ;
26- const client_id = process . env . AGENTCONNECT_CLIENTID ;
27- const client_secret = process . env . AGENTCONNECT_SECRET ;
26+ const client_id = this . configService . get ( 'AGENTCONNECT_CLIENTID' ) ;
27+ const client_secret = this . configService . get ( 'AGENTCONNECT_SECRET' ) ;
2828 const redirect_uri =
29- process . env . AGENTCONNECT_REDIRECT_URL + '/login_callback' ;
29+ this . configService . get ( ' AGENTCONNECT_REDIRECT_URL' ) + '/login_callback' ;
3030
3131 if ( sendedState !== state ) {
3232 this . logger . warn (
@@ -41,7 +41,7 @@ export class AuthenticationService {
4141 const {
4242 data : { access_token : accessToken , id_token : idToken } ,
4343 } = await this . httpService . axiosRef . post (
44- `${ process . env . AGENTCONNECT_URL } /api/v2/token` ,
44+ `${ this . configService . get ( ' AGENTCONNECT_URL' ) } /api/v2/token` ,
4545 queryString . stringify ( {
4646 grant_type : 'authorization_code' ,
4747 code,
@@ -54,19 +54,23 @@ export class AuthenticationService {
5454 'Content-Type' : 'application/x-www-form-urlencoded' ,
5555 } ,
5656 proxy : false ,
57- httpsAgent : new HttpsProxyAgent ( process . env . AGENTCONNECT_PROXYURL ) ,
57+ httpsAgent : new HttpsProxyAgent (
58+ this . configService . get ( 'AGENTCONNECT_PROXYURL' ) ,
59+ ) ,
5860 } ,
5961 ) ;
6062 this . logger . log (
6163 "accessToken récupéré d'agentConnect {/authentication/login_callback} route" ,
6264 ) ;
6365
6466 const { data : userinfo } = await this . httpService . axiosRef . get (
65- `${ process . env . AGENTCONNECT_URL } /api/v2/userinfo` ,
67+ `${ this . configService . get ( ' AGENTCONNECT_URL' ) } /api/v2/userinfo` ,
6668 {
6769 headers : { Authorization : `Bearer ${ accessToken } ` } ,
6870 proxy : false ,
69- httpsAgent : new HttpsProxyAgent ( process . env . AGENTCONNECT_PROXYURL ) ,
71+ httpsAgent : new HttpsProxyAgent (
72+ this . configService . get ( 'AGENTCONNECT_PROXYURL' ) ,
73+ ) ,
7074 } ,
7175 ) ;
7276 this . logger . log (
@@ -77,6 +81,7 @@ export class AuthenticationService {
7781 } catch ( error ) {
7882 this . logger . error (
7983 "erreur lors de récupération de l'accessToken ou userinfo d'agentConnect" ,
84+ error ,
8085 ) ;
8186 throw new NotFoundException (
8287 "erreur lors de récupération de l'accessToken ou userinfo d'agentConnect" ,
@@ -90,9 +95,11 @@ export class AuthenticationService {
9095 id_token_hint : idToken ,
9196 state,
9297 post_logout_redirect_uri :
93- process . env . AGENTCONNECT_REDIRECT_URL + '/logout_callback' ,
98+ this . configService . get ( 'AGENTCONNECT_REDIRECT_URL' ) +
99+ '/logout_callback' ,
94100 } ;
95- const url = process . env . AGENTCONNECT_URL + '/api/v2/session/end' + '?' ;
101+ const url =
102+ this . configService . get ( 'AGENTCONNECT_URL' ) + '/api/v2/session/end' + '?' ;
96103 return url + queryString . stringify ( query ) ;
97104 }
98105}
0 commit comments