FEAT: passport mailchimp

This commit is contained in:
Gabriel Rosa
2022-06-27 17:50:45 -03:00
parent b584c80e24
commit 91aefe7d61
6 changed files with 34 additions and 29 deletions
+2
View File
@@ -36,6 +36,7 @@ import { FacebookStrategy } from './modules/oauth/passport-strategies/facebook-s
import { AuthenticationGuard } from './authentication/authentication.guard';
import { APP_GUARD } from '@nestjs/core';
import { GoogleStrategy } from './modules/oauth/passport-strategies/google-strategy';
import { MailChimpStrategy } from './modules/oauth/passport-strategies/mailchimp-strategy';
const ducClient = new DucClient();
const inputClient = new InputsClientConfiguration();
@@ -76,6 +77,7 @@ const transformationClient = new TransformationsClientConfiguration();
HubspotStrategy,
FacebookStrategy,
GoogleStrategy,
MailChimpStrategy,
],
imports: [
ConfigModule.forRoot({
+13
View File
@@ -76,6 +76,19 @@ export class OauthController {
return await this.callback(req, 'facebook');
}
@Get('mailchimp')
@UseGuards(AuthGuard('mailchimp'))
async oauthMailchimp() {
return true;
}
@Get('mailchimp/callback')
@UseGuards(AuthGuard('mailchimp'))
@Redirect()
async oauthMailchimpCallback(@Req() req) {
return await this.callback(req, 'mailchimp');
}
async callback(@Req() req: Request, plugin) {
const { error, state: customer_id } = req.query;
@@ -15,9 +15,9 @@ export class FacebookStrategy extends PassportStrategy(Strategy) {
private readonly oauthSecrets: OauthSecrets,
) {
const options: StrategyOptionWithRequest = {
clientID: oauthSecrets.google.client_id,
clientSecret: oauthSecrets.google.client_secret,
callbackURL: oauthSecrets.google.redirect_uri,
clientID: oauthSecrets.facebook.client_id,
clientSecret: oauthSecrets.facebook.client_secret,
callbackURL: oauthSecrets.facebook.redirect_uri,
passReqToCallback: true,
};
const verify: VerifyFunction = (
@@ -29,11 +29,4 @@ export class FacebookStrategy extends PassportStrategy(Strategy) {
super(options, verify);
}
authenticate(req, options) {
const { customer_id } = req.query;
options.state = customer_id;
options.scope = 'ads_management ads_read';
super.authenticate(req, options);
}
}
@@ -1,31 +1,26 @@
import { Profile, Strategy, StrategyOptions } from 'passport-google-oauth20';
import { Strategy } from 'passport-mailchimp';
import { PassportStrategy } from '@nestjs/passport';
import { Inject, Injectable, Req } from '@nestjs/common';
import { OauthSecrets } from 'src/utils/OauthSecrets';
@Injectable()
export class MailChimpStrategy extends PassportStrategy(Strategy, 'google') {
export class MailChimpStrategy extends PassportStrategy(Strategy, 'mailchimp') {
constructor(
@Inject('OAUTH_SECRETS')
private readonly oauthSecrets: OauthSecrets,
) {
const options: StrategyOptions = {
const options = {
clientID: oauthSecrets.mailchimp.client_id,
clientSecret: oauthSecrets.mailchimp.client_secret,
callbackURL: oauthSecrets.mailchimp.redirect_uri,
scope: [
'https://www.googleapis.com/auth/drive.metadata.readonly',
'https://www.googleapis.com/auth/spreadsheets.readonly',
'https://www.googleapis.com/auth/userinfo.email',
],
scope: '',
};
const verify = (
accessToken: string,
refreshToken: string,
profile: Profile,
profile: any,
done,
) => {
console.log('verify');
return done(null, profile, { accessToken, refreshToken });
};
@@ -35,13 +30,6 @@ export class MailChimpStrategy extends PassportStrategy(Strategy, 'google') {
authenticate(@Req() req, options) {
const { customer_id } = req.query;
options.state = customer_id;
options.accessType = 'offline';
options.prompt = 'consent';
super.authenticate(req, options);
}
async validate(...args) {
console.log('validate');
console.log(args);
}
}
+10 -1
View File
@@ -13,6 +13,7 @@ export class OauthSecrets {
hubspot = new OauthSecretsObject();
google = new OauthSecretsObject();
mailchimp = new OauthSecretsObject();
facebook = new OauthSecretsObject();
}
export async function getOauthSecrets() {
const secrets = new OauthSecrets();
@@ -25,7 +26,15 @@ export async function getOauthSecrets() {
const res = await secretsManagerClient
.send(getSecretComand)
.catch(() => null);
if (res) secrets[key] = JSON.parse(res.SecretString);
if (res) {
secrets[key] = JSON.parse(res.SecretString);
} else {
secrets[key] = {
client_id: 'id',
client_secret: 'id',
redirect_uri: 'id',
};
}
}
return secrets;
}
+1 -1
View File
File diff suppressed because one or more lines are too long