add launcher oauth exchange api
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "atnmy-stdo-v2-be",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
"description": "",
|
||||
"author": "",
|
||||
"private": true,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Delete, Get, Post, Put, Req, Res } from '@nestjs/common';
|
||||
import { BadRequestException, Body, Controller, Delete, Get, Post, Put, Req, Res } from '@nestjs/common';
|
||||
import type { Request, Response } from 'express';
|
||||
|
||||
import { AuthService } from './auth.service';
|
||||
@@ -32,6 +32,23 @@ export class AuthController {
|
||||
return this.authService.refresh(request.headers.cookie, response);
|
||||
}
|
||||
|
||||
@Post('oauth/exchange')
|
||||
exchangeOAuthLoginToken(
|
||||
@Body() body: { loginToken?: string },
|
||||
@Req() request: Request,
|
||||
@Res({ passthrough: true }) response: Response,
|
||||
) {
|
||||
if (!body.loginToken) {
|
||||
throw new BadRequestException('loginToken is required');
|
||||
}
|
||||
|
||||
return this.authService.exchangeOAuthLoginToken(
|
||||
body.loginToken,
|
||||
request.headers.cookie,
|
||||
response,
|
||||
);
|
||||
}
|
||||
|
||||
@Post('logout')
|
||||
logout(
|
||||
@Req() request: Request,
|
||||
|
||||
@@ -63,6 +63,25 @@ export class AuthService {
|
||||
return this.frontendTokenResponse(authResponse);
|
||||
}
|
||||
|
||||
async exchangeOAuthLoginToken(
|
||||
loginToken: string,
|
||||
cookieHeader: string | undefined,
|
||||
response: Response,
|
||||
) {
|
||||
const authResponse = await this.request<AuthTokenResponse>(
|
||||
'/auth/oauth/exchange',
|
||||
{
|
||||
method: 'POST',
|
||||
body: { loginToken },
|
||||
cookieHeader,
|
||||
response,
|
||||
unauthorizedMessage: 'Invalid Google login session',
|
||||
},
|
||||
);
|
||||
|
||||
return this.frontendTokenResponse(authResponse);
|
||||
}
|
||||
|
||||
async logout(
|
||||
cookieHeader: string | undefined,
|
||||
response: Response,
|
||||
|
||||
Reference in New Issue
Block a user