mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-28 10:20:06 +00:00
FIX: google strategy custom scopes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Profile, Strategy, StrategyOptions } from 'passport-google-oauth20';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { Inject, Injectable, Req } from '@nestjs/common';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { OauthSecrets } from 'src/utils/OauthSecrets';
|
||||
|
||||
@Injectable()
|
||||
@@ -12,12 +12,7 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
|
||||
const options: StrategyOptions = {
|
||||
clientID: oauthSecrets.google.client_id,
|
||||
clientSecret: oauthSecrets.google.client_secret,
|
||||
scope: [
|
||||
'https://www.googleapis.com/auth/drive.metadata.readonly',
|
||||
'https://www.googleapis.com/auth/spreadsheets.readonly',
|
||||
'https://www.googleapis.com/auth/userinfo.email',
|
||||
],
|
||||
callbackURL: oauthSecrets.google.redirect_uri,
|
||||
callbackURL: '/oauth/googleads/callback',
|
||||
};
|
||||
const verify = (
|
||||
accessToken: string,
|
||||
@@ -32,16 +27,21 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
|
||||
super(options, verify);
|
||||
}
|
||||
|
||||
authenticate(@Req() req, options) {
|
||||
authenticate(req, options) {
|
||||
const path: string = req.route.path;
|
||||
const { customer_id } = req.query;
|
||||
const scope: string[] = ['https://www.googleapis.com/auth/userinfo.email'];
|
||||
if (path.includes('googleads'))
|
||||
scope.push('https://www.googleapis.com/auth/adwords');
|
||||
if (path.includes('google-sheets'))
|
||||
scope.push(
|
||||
'https://www.googleapis.com/auth/drive.metadata.readonly',
|
||||
'https://www.googleapis.com/auth/spreadsheets.readonly',
|
||||
);
|
||||
options.scope = scope;
|
||||
options.state = customer_id;
|
||||
options.accessType = 'offline';
|
||||
options.prompt = 'consent';
|
||||
super.authenticate(req, options);
|
||||
}
|
||||
|
||||
async validate(...args) {
|
||||
console.log('validate');
|
||||
console.log(args);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user