mirror of
https://github.com/dadosfera/maestro.git
synced 2026-10-05 02:49:09 +00:00
FIX: google strategy custom scopes
This commit is contained in:
@@ -1,11 +1,4 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
Controller,
|
||||
Get,
|
||||
Redirect,
|
||||
Req,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { Controller, Get, Redirect, Req, UseGuards } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { InputsClientService } from 'src/clients/inputs/client.service';
|
||||
@@ -54,7 +47,32 @@ export class OauthController {
|
||||
@UseGuards(AuthGuard('google'))
|
||||
@Redirect()
|
||||
async oauthGoogleCallback(@Req() req) {
|
||||
return await this.callback(req, 'google');
|
||||
return await this.callback(req, 'googleads');
|
||||
}
|
||||
@Get('googleads')
|
||||
@UseGuards(AuthGuard('google'))
|
||||
async oauthGoogleAds() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Get('googleads/callback')
|
||||
@UseGuards(AuthGuard('google'))
|
||||
@Redirect()
|
||||
async oauthGoogleAdsCallback(@Req() req) {
|
||||
return await this.callback(req, 'googleads');
|
||||
}
|
||||
|
||||
@Get('google-sheets')
|
||||
@UseGuards(AuthGuard('google'))
|
||||
async oauthGoogleSheets() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Get('google-sheets/callback')
|
||||
@UseGuards(AuthGuard('google'))
|
||||
@Redirect()
|
||||
async oauthGoogleSheetsCallback(@Req() req) {
|
||||
return await this.callback(req, 'google-sheets');
|
||||
}
|
||||
|
||||
@Get('facebook')
|
||||
@@ -70,15 +88,22 @@ export class OauthController {
|
||||
return await this.callback(req, 'facebook');
|
||||
}
|
||||
|
||||
async callback(@Req() req, plugin) {
|
||||
const { authInfo } = req;
|
||||
async callback(@Req() req: Request, plugin) {
|
||||
const { error, state: customer_id } = req.query;
|
||||
|
||||
const request: Request = req;
|
||||
if (error)
|
||||
return {
|
||||
url: `${this.frontendRedirectUri}?error=${error}`,
|
||||
};
|
||||
const request: any = req;
|
||||
const { authInfo } = request;
|
||||
|
||||
if (!authInfo) throw new BadRequestException('Oauth tokens not found');
|
||||
if (!authInfo)
|
||||
return {
|
||||
url: `${this.frontendRedirectUri}?error=invalid_credentials`,
|
||||
};
|
||||
|
||||
const { accessToken: access_token, refreshToken: refresh_token } = authInfo;
|
||||
const { state: customer_id } = request.query;
|
||||
|
||||
const response = await this.inputService.create({
|
||||
info: { customer_id, customer: 'customer', user_id: 'empty' },
|
||||
|
||||
Reference in New Issue
Block a user