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
+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);
}
}