From b3660fbb69d444945e77404960c418693518146d Mon Sep 17 00:00:00 2001 From: "makabe.t" Date: Thu, 16 Nov 2023 06:50:42 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20581:=20=E5=AF=BE=E5=BF=9C?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3115: 対応する](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3115) - 利用規約同意後のログイン遷移に失敗する問題に対応しました。 - 原因は利用規約未同意でログインに失敗した場合もIDトークンの保存をしていたことでした。 そのため、同意後に同一のIDトークンでログインしようとすると保存済みとして失敗していました。  - 対応として、IDトークンの保存は利用規約同意が最新化チェックした後に実行するようにしました。 ## レビューポイント - キャッシュへの保存処理を利用規約同意のチェック後に移動しましたが何か不都合などないでしょうか? ## UIの変更 なし ## 動作確認状況 - ローカルで確認 --- .../src/features/auth/auth.controller.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/dictation_server/src/features/auth/auth.controller.ts b/dictation_server/src/features/auth/auth.controller.ts index 32d7697..d756f8d 100644 --- a/dictation_server/src/features/auth/auth.controller.ts +++ b/dictation_server/src/features/auth/auth.controller.ts @@ -40,8 +40,6 @@ import { RedisService } from '../../gateways/redis/redis.service'; @Controller('auth') export class AuthController { constructor( - // TODO「タスク 1828: IDトークンを一度しか使えないようにする」で使用する予定 - // private readonly redisService: RedisService, private readonly authService: AuthService, private readonly redisService: RedisService, ) {} @@ -78,20 +76,18 @@ export class AuthController { ); } - const context = makeContext(uuidv4()); + const context = makeContext(idToken.sub); const key = makeIDTokenKey(body.idToken); const isTokenExists = await this.redisService.get(key); - if (!isTokenExists) { - // IDトークンがキャッシュに存在しない場合(idTokenの有効期限をADB2Cの有効期限と合わせる(300秒)) - await this.redisService.set(key, true, 300); - } else { + if (isTokenExists) { // IDトークンがキャッシュに存在する場合エラー throw new HttpException( makeErrorResponse('E000106'), HttpStatus.UNAUTHORIZED, ); } + // 同意済み利用規約バージョンが最新かチェック const isAcceptedLatestVersion = await this.authService.isAcceptedLatestVersion(context, idToken); @@ -104,6 +100,9 @@ export class AuthController { ); } + // IDトークンをキャッシュに保存(idTokenの有効期限をADB2Cの有効期限と合わせる(300秒)) + await this.redisService.set(key, true, 300); + const refreshToken = await this.authService.generateRefreshToken( context, idToken,