FEAT: passport facebook

This commit is contained in:
Gabriel Rosa
2022-06-30 12:35:47 -03:00
parent aaf99b8c2e
commit b03b8f3b08
@@ -1,12 +1,15 @@
import {
Profile,
Strategy,
StrategyOptionWithRequest,
StrategyOption,
VerifyFunction,
} from 'passport-facebook';
import { PassportStrategy } from '@nestjs/passport';
import { Inject, Injectable } from '@nestjs/common';
import { OauthSecrets } from 'src/utils/OauthSecrets';
import { Request } from 'express';
import { ParamsDictionary } from 'express-serve-static-core';
import { ParsedQs } from 'qs';
@Injectable()
export class FacebookStrategy extends PassportStrategy(Strategy) {
@@ -14,19 +17,29 @@ export class FacebookStrategy extends PassportStrategy(Strategy) {
@Inject('OAUTH_SECRETS')
private readonly oauthSecrets: OauthSecrets,
) {
const options: StrategyOptionWithRequest = {
const options: StrategyOption = {
clientID: oauthSecrets.facebook.client_id,
clientSecret: oauthSecrets.facebook.client_secret,
callbackURL: oauthSecrets.facebook.redirect_uri,
passReqToCallback: true,
};
const verify: VerifyFunction = (
accessToken: string,
refreshToken: string,
profile: Profile,
done: (error: any, user?: any, info?: any) => void,
) => done(null, profile, { accessToken, refreshToken });
) => {
return done(null, profile, { accessToken, refreshToken });
};
super(options, verify);
}
authenticate(
req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>,
options?: any,
): void {
const { customer_id } = req.query;
options.state = customer_id;
options.scope = 'ads_read ads_management';
super.authenticate(req, options);
}
}