mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-13 06:19:08 +00:00
FIX: google redirect uri fixed
This commit is contained in:
@@ -5,6 +5,7 @@ import { OauthSecrets } from 'src/utils/OauthSecrets';
|
||||
|
||||
@Injectable()
|
||||
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
|
||||
redirect_uri: string;
|
||||
constructor(
|
||||
@Inject('OAUTH_SECRETS')
|
||||
private readonly oauthSecrets: OauthSecrets,
|
||||
@@ -25,24 +26,42 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
|
||||
};
|
||||
|
||||
super(options, verify);
|
||||
switch (process.env.ENV) {
|
||||
case 'dev':
|
||||
case 'stg':
|
||||
this.redirect_uri = `https://maestro.${process.env.ENV}.dadosfera.ai/oauth`;
|
||||
break;
|
||||
case 'prd':
|
||||
this.redirect_uri = `https://maestro.dadosfera.ai/oauth`;
|
||||
break;
|
||||
default:
|
||||
this.redirect_uri = `/oauth`;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
authenticate(req, options) {
|
||||
const path: string = req.route.path;
|
||||
if (req.route.path.includes('callback')) {
|
||||
return super.authenticate(req, options);
|
||||
}
|
||||
|
||||
const plugin: string = req.route.path.replace('/oauth/', '');
|
||||
|
||||
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');
|
||||
options.callbackURL = '/oauth/googleads/callback';
|
||||
options.scope = ['https://www.googleapis.com/auth/userinfo.email'];
|
||||
options.callbackURL = `${this.redirect_uri}/${plugin}/callback`;
|
||||
|
||||
switch (plugin) {
|
||||
case 'googleads':
|
||||
options.scope.push('https://www.googleapis.com/auth/adwords');
|
||||
break;
|
||||
case 'google-sheets':
|
||||
options.scope.push(
|
||||
'https://www.googleapis.com/auth/drive.metadata.readonly',
|
||||
'https://www.googleapis.com/auth/spreadsheets.readonly',
|
||||
);
|
||||
break;
|
||||
}
|
||||
if (path.includes('google-sheets')) {
|
||||
scope.push(
|
||||
'https://www.googleapis.com/auth/drive.metadata.readonly',
|
||||
'https://www.googleapis.com/auth/spreadsheets.readonly',
|
||||
);
|
||||
options.callbackURL = '/oauth/google-sheets/callback';
|
||||
}
|
||||
options.scope = scope;
|
||||
options.state = customer_id;
|
||||
options.accessType = 'offline';
|
||||
options.prompt = 'consent';
|
||||
|
||||
Reference in New Issue
Block a user