Skip to content

Commit 2c25794

Browse files
committed
deploy: e1f1eb3
1 parent b8ced06 commit 2c25794

29 files changed

+1186
-1124
lines changed

controllers/AuthController.html

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ <h3 id="methods">
225225

226226
<tr>
227227
<td class="col-md-4">
228-
<div class="io-line">Defined in <a href="" data-line="26"
229-
class="link-to-prism">src/core/auth/auth.controller.ts:26</a></div>
228+
<div class="io-line">Defined in <a href="" data-line="28"
229+
class="link-to-prism">src/core/auth/auth.controller.ts:28</a></div>
230230
</td>
231231
</tr>
232232

@@ -316,8 +316,8 @@ <h3 id="methods">
316316

317317
<tr>
318318
<td class="col-md-4">
319-
<div class="io-line">Defined in <a href="" data-line="60"
320-
class="link-to-prism">src/core/auth/auth.controller.ts:60</a></div>
319+
<div class="io-line">Defined in <a href="" data-line="62"
320+
class="link-to-prism">src/core/auth/auth.controller.ts:62</a></div>
321321
</td>
322322
</tr>
323323

@@ -407,8 +407,8 @@ <h3 id="methods">
407407

408408
<tr>
409409
<td class="col-md-4">
410-
<div class="io-line">Defined in <a href="" data-line="50"
411-
class="link-to-prism">src/core/auth/auth.controller.ts:50</a></div>
410+
<div class="io-line">Defined in <a href="" data-line="52"
411+
class="link-to-prism">src/core/auth/auth.controller.ts:52</a></div>
412412
</td>
413413
</tr>
414414

@@ -499,8 +499,8 @@ <h3 id="methods">
499499

500500
<tr>
501501
<td class="col-md-4">
502-
<div class="io-line">Defined in <a href="" data-line="37"
503-
class="link-to-prism">src/core/auth/auth.controller.ts:37</a></div>
502+
<div class="io-line">Defined in <a href="" data-line="39"
503+
class="link-to-prism">src/core/auth/auth.controller.ts:39</a></div>
504504
</td>
505505
</tr>
506506

@@ -572,6 +572,8 @@ <h3 id="methods">
572572
import { Response } from &#x27;express&#x27;;
573573
import { ReqIdentity } from &#x27;~/_common/decorators/params/req-identity.decorator&#x27;;
574574
import { AgentType } from &#x27;~/_common/types/agent.type&#x27;;
575+
import { hash } from &#x27;crypto&#x27;;
576+
import { omit } from &#x27;radash&#x27;;
575577

576578
@Public()
577579
@ApiTags(&#x27;core/auth&#x27;)
@@ -602,8 +604,8 @@ <h3 id="methods">
602604
const user &#x3D; await this.service.getSessionData(identity);
603605
return res.status(HttpStatus.OK).json({
604606
user: {
605-
...user,
606-
sseToken: &#x27;hZcdVqHScVDsDFdHOdcjmufEKFJVKaS8&#x27;, //TODO: change to real token
607+
...omit(user, [&#x27;security&#x27;]),
608+
sseToken: hash(&#x27;sha256&#x27;, user.security.secretKey),
607609
},
608610
});
609611
}
@@ -612,10 +614,10 @@ <h3 id="methods">
612614
@Post(&#x27;refresh&#x27;)
613615
@ApiOperation({ summary: &quot;Récupère un nouveau jeton d&#x27;authentification&quot; })
614616
public async refresh(@Res() res: Response, @Body() body: { refresh_token: string }): Promise&lt;Response&gt; {
615-
const tokens &#x3D; await this.service.renewTokens(body.refresh_token);
617+
const [agents, tokens] &#x3D; await this.service.renewTokens(body.refresh_token);
616618
return res.status(HttpStatus.OK).json({
617619
...tokens,
618-
sseToken: &#x27;hZcdVqHScVDsDFdHOdcjmufEKFJVKaS8&#x27;, //TODO: change to real token
620+
sseToken: hash(&#x27;sha256&#x27;, agents.security.secretKey),
619621
});
620622
}
621623

controllers/BackendsController.html

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ <h3 id="methods">
225225

226226
<tr>
227227
<td class="col-md-4">
228-
<div class="io-line">Defined in <a href="" data-line="49"
229-
class="link-to-prism">src/core/backends/backends.controller.ts:49</a></div>
228+
<div class="io-line">Defined in <a href="" data-line="54"
229+
class="link-to-prism">src/core/backends/backends.controller.ts:54</a></div>
230230
</td>
231231
</tr>
232232

@@ -328,8 +328,8 @@ <h3 id="methods">
328328

329329
<tr>
330330
<td class="col-md-4">
331-
<div class="io-line">Defined in <a href="" data-line="89"
332-
class="link-to-prism">src/core/backends/backends.controller.ts:89</a></div>
331+
<div class="io-line">Defined in <a href="" data-line="94"
332+
class="link-to-prism">src/core/backends/backends.controller.ts:94</a></div>
333333
</td>
334334
</tr>
335335

@@ -466,7 +466,7 @@ <h3 id="methods">
466466
<tr>
467467
<td class="col-md-4">
468468
<span class="modifier-icon icon ion-ios-reset"></span>
469-
<code>sse(res: Response, key: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank">string</a>)</code>
469+
<code>sse(res: Response, id: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank">string</a>, key: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank">string</a>)</code>
470470
</td>
471471
</tr>
472472

@@ -480,8 +480,8 @@ <h3 id="methods">
480480

481481
<tr>
482482
<td class="col-md-4">
483-
<div class="io-line">Defined in <a href="" data-line="127"
484-
class="link-to-prism">src/core/backends/backends.controller.ts:127</a></div>
483+
<div class="io-line">Defined in <a href="" data-line="132"
484+
class="link-to-prism">src/core/backends/backends.controller.ts:132</a></div>
485485
</td>
486486
</tr>
487487

@@ -512,6 +512,18 @@ <h3 id="methods">
512512
</td>
513513

514514

515+
</tr>
516+
<tr>
517+
<td>id</td>
518+
<td>
519+
<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
520+
</td>
521+
522+
<td>
523+
No
524+
</td>
525+
526+
515527
</tr>
516528
<tr>
517529
<td>key</td>
@@ -571,8 +583,8 @@ <h3 id="methods">
571583

572584
<tr>
573585
<td class="col-md-4">
574-
<div class="io-line">Defined in <a href="" data-line="79"
575-
class="link-to-prism">src/core/backends/backends.controller.ts:79</a></div>
586+
<div class="io-line">Defined in <a href="" data-line="84"
587+
class="link-to-prism">src/core/backends/backends.controller.ts:84</a></div>
576588
</td>
577589
</tr>
578590

@@ -662,8 +674,8 @@ <h3 id="methods">
662674

663675
<tr>
664676
<td class="col-md-4">
665-
<div class="io-line">Defined in <a href="" data-line="64"
666-
class="link-to-prism">src/core/backends/backends.controller.ts:64</a></div>
677+
<div class="io-line">Defined in <a href="" data-line="69"
678+
class="link-to-prism">src/core/backends/backends.controller.ts:69</a></div>
667679
</td>
668680
</tr>
669681

@@ -746,12 +758,13 @@ <h3 id="methods">
746758
ParseIntPipe,
747759
Post,
748760
Query,
761+
Req,
749762
Res,
750763
Sse,
751764
UnauthorizedException,
752765
} from &#x27;@nestjs/common&#x27;;
753766
import { ApiOperation, ApiTags } from &#x27;@nestjs/swagger&#x27;;
754-
import { Response } from &#x27;express&#x27;;
767+
import { Response, Request } from &#x27;express&#x27;;
755768
import Redis from &#x27;ioredis&#x27;;
756769
import { Observable, Subscriber } from &#x27;rxjs&#x27;;
757770
import { Public } from &#x27;~/_common/decorators/public.decorator&#x27;;
@@ -761,6 +774,9 @@ <h3 id="methods">
761774
import { Types } from &#x27;mongoose&#x27;;
762775
import { ActionType } from &#x27;./_enum/action-type.enum&#x27;;
763776
import { DeleteIdentitiesDto } from &#x27;./_dto/delete-identities.dto&#x27;;
777+
import { hash } from &#x27;crypto&#x27;;
778+
import { AgentsService } from &#x27;../agents/agents.service&#x27;;
779+
import { Agents } from &#x27;../agents/_schemas/agents.schema&#x27;;
764780

765781
function fireMessage(observer: Subscriber&lt;MessageEvent&gt;, channel: string, message: any, loggername: string) {
766782
try {
@@ -779,6 +795,7 @@ <h3 id="methods">
779795
private readonly logger &#x3D; new Logger(BackendsController.name);
780796

781797
constructor(
798+
private agentsService: AgentsService,
782799
private backendsService: BackendsService,
783800
@InjectRedis() protected readonly redis: Redis,
784801
) { }
@@ -863,8 +880,11 @@ <h3 id="methods">
863880
@Public()
864881
@Sse(&#x27;sse&#x27;)
865882
@ApiOperation({ summary: &#x27;Server Sent Event - Récupère en temps réel les Jobs et affiche leurs état&#x27; })
866-
public async sse(@Res() res: Response, @Query(&#x27;key&#x27;) key: string): Promise&lt;Observable&lt;MessageEvent&gt;&gt; {
867-
if (key !&#x3D;&#x3D; &#x27;hZcdVqHScVDsDFdHOdcjmufEKFJVKaS8&#x27;) throw new UnauthorizedException();
883+
public async sse(@Res() res: Response, @Query(&#x27;id&#x27;) id: string, @Query(&#x27;key&#x27;) key: string): Promise&lt;Observable&lt;MessageEvent&gt;&gt; {
884+
if (!id || !key) throw new UnauthorizedException();
885+
const user &#x3D; await this.agentsService.findById&lt;Agents&gt;(id);
886+
if (!user) throw new UnauthorizedException();
887+
if (key !&#x3D;&#x3D; hash(&#x27;sha256&#x27;, user.security.secretKey)) throw new UnauthorizedException();
868888

869889
res.socket.on(&#x27;close&#x27;, () &#x3D;&gt; {
870890
Logger.debug(&#x60;Observer close connection&#x60;, this.constructor.name);

0 commit comments

Comments
 (0)