mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-29 20:50:05 +00:00
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { Strategy } from 'passport-mailchimp';
|
|
import { PassportStrategy } from '@nestjs/passport';
|
|
import { Inject, Injectable, Req } from '@nestjs/common';
|
|
import { OauthSecrets } from 'src/utils/OauthSecrets';
|
|
import { OauthService } from '../oauth.service';
|
|
|
|
@Injectable()
|
|
export class MailChimpStrategy extends PassportStrategy(Strategy, 'mailchimp') {
|
|
constructor(
|
|
@Inject('OAUTH_SECRETS')
|
|
private readonly oauthSecrets: OauthSecrets,
|
|
private oauthService: OauthService,
|
|
) {
|
|
const options = {
|
|
clientID: oauthSecrets.mailchimp.client_id,
|
|
clientSecret: oauthSecrets.mailchimp.client_secret,
|
|
callbackURL: oauthSecrets.mailchimp.redirect_uri,
|
|
scope: '',
|
|
};
|
|
const verify = (
|
|
accessToken: string,
|
|
refreshToken: string,
|
|
profile: any,
|
|
done,
|
|
) => {
|
|
return done(null, profile, { accessToken, refreshToken });
|
|
};
|
|
|
|
super(options, verify);
|
|
}
|
|
|
|
authenticate(@Req() req, options) {
|
|
if (!req.route.path.includes('callback'))
|
|
options.state = this.oauthService.generateStateFromRequest(
|
|
options.state,
|
|
req,
|
|
'application',
|
|
);
|
|
super.authenticate(req, options);
|
|
}
|
|
}
|