add launcher oauth exchange api
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "atnmy-stdo-v2-be",
|
"name": "atnmy-stdo-v2-be",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "",
|
"author": "",
|
||||||
"private": true,
|
"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 type { Request, Response } from 'express';
|
||||||
|
|
||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
@@ -32,6 +32,23 @@ export class AuthController {
|
|||||||
return this.authService.refresh(request.headers.cookie, response);
|
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')
|
@Post('logout')
|
||||||
logout(
|
logout(
|
||||||
@Req() request: Request,
|
@Req() request: Request,
|
||||||
|
|||||||
@@ -63,6 +63,25 @@ export class AuthService {
|
|||||||
return this.frontendTokenResponse(authResponse);
|
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(
|
async logout(
|
||||||
cookieHeader: string | undefined,
|
cookieHeader: string | undefined,
|
||||||
response: Response,
|
response: Response,
|
||||||
|
|||||||
Reference in New Issue
Block a user