mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-10 14:59:07 +00:00
New strategies
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
Profile,
|
||||
Strategy,
|
||||
StrategyOptionWithRequest,
|
||||
VerifyFunction,
|
||||
} from 'passport-facebook';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { OauthSecrets } from 'src/utils/OauthSecrets';
|
||||
|
||||
@Injectable()
|
||||
export class FacebookStrategy extends PassportStrategy(Strategy) {
|
||||
constructor(
|
||||
@Inject('OAUTH_SECRETS')
|
||||
private readonly oauthSecrets: OauthSecrets,
|
||||
) {
|
||||
const options: StrategyOptionWithRequest = {
|
||||
clientID: oauthSecrets.google.client_id,
|
||||
clientSecret: oauthSecrets.google.client_secret,
|
||||
callbackURL: oauthSecrets.google.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 });
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
Profile,
|
||||
Strategy,
|
||||
StrategyOptionsWithRequest,
|
||||
VerifyCallback,
|
||||
} from 'passport-google-oauth20';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { OauthSecrets } from 'src/utils/OauthSecrets';
|
||||
|
||||
@Injectable()
|
||||
export class GoogleStrategy extends PassportStrategy(Strategy) {
|
||||
constructor(
|
||||
@Inject('OAUTH_SECRETS')
|
||||
private readonly oauthSecrets: OauthSecrets,
|
||||
) {
|
||||
const options: StrategyOptionsWithRequest = {
|
||||
clientID: oauthSecrets.google.client_id,
|
||||
clientSecret: oauthSecrets.google.client_secret,
|
||||
scope: 'drive.metadata.readonly spreadsheets.readonly',
|
||||
callbackURL: oauthSecrets.google.redirect_uri,
|
||||
passReqToCallback: true,
|
||||
};
|
||||
const verify = (
|
||||
accessToken: string,
|
||||
refreshToken: string,
|
||||
profile: Profile,
|
||||
done: VerifyCallback,
|
||||
) => done(null, profile, { accessToken, refreshToken });
|
||||
|
||||
super(options, verify);
|
||||
}
|
||||
|
||||
authenticate(req, options) {
|
||||
const { customer_id } = req.query;
|
||||
options.state = customer_id;
|
||||
super.authenticate(req, options);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user