mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-22 20:39:17 +08:00
Update passport-facebook-token types
* Duplicate imports are no longer necessary with this change
This commit is contained in:
19
types/passport-facebook-token/index.d.ts
vendored
19
types/passport-facebook-token/index.d.ts
vendored
@@ -7,15 +7,17 @@
|
||||
import * as passport from 'passport';
|
||||
import * as express from 'express';
|
||||
|
||||
declare class Strategy implements passport.Strategy {
|
||||
constructor(options: Strategy.StrategyOptionsWithRequest, verify: Strategy.VerifyFunctionWithRequest)
|
||||
constructor(options: Strategy.StrategyOptions, verify: Strategy.VerifyFunction);
|
||||
declare namespace PassportFacebookToken {
|
||||
interface StrategyStatic {
|
||||
new(options: StrategyOptionsWithRequest, verify: VerifyFunctionWithRequest): StrategyInstance;
|
||||
new(options: StrategyOptions, verify: VerifyFunction): StrategyInstance;
|
||||
}
|
||||
|
||||
name: string;
|
||||
authenticate: (req: express.Request, options?: any) => void;
|
||||
}
|
||||
interface StrategyInstance {
|
||||
name: string;
|
||||
authenticate: (req: express.Request, options?: any) => void;
|
||||
}
|
||||
|
||||
declare namespace Strategy {
|
||||
interface ValueObject {
|
||||
value: string;
|
||||
}
|
||||
@@ -55,4 +57,5 @@ declare namespace Strategy {
|
||||
type VerifyFunctionWithRequest = (req: express.Request, accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any, info?: any) => void) => void;
|
||||
}
|
||||
|
||||
export = Strategy;
|
||||
declare const PassportFacebookToken: PassportFacebookToken.StrategyStatic;
|
||||
export = PassportFacebookToken;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import * as express from 'express';
|
||||
import * as passport from 'passport';
|
||||
import * as FacebookStrategy from 'passport-facebook-token';
|
||||
// tslint:disable-next-line:no-duplicate-imports
|
||||
import { StrategyOptions, StrategyOptionsWithRequest, VerifyFunction, VerifyFunctionWithRequest, Profile } from 'passport-facebook-token';
|
||||
import * as PassportFacebookToken from 'passport-facebook-token';
|
||||
|
||||
const User = {
|
||||
findOrCreate(id: string, provider: string, callback: (err: any, user: any) => void): void {
|
||||
@@ -10,18 +8,19 @@ const User = {
|
||||
}
|
||||
};
|
||||
|
||||
const options: StrategyOptions = {
|
||||
const options: PassportFacebookToken.StrategyOptions = {
|
||||
clientID: 'TEST_CLIENT_ID',
|
||||
clientSecret: 'TEST_CLIENT_SECRET'
|
||||
};
|
||||
|
||||
const optionsWithRequest: StrategyOptionsWithRequest = {
|
||||
const optionsWithRequest: PassportFacebookToken.StrategyOptionsWithRequest = {
|
||||
clientID: 'TEST_CLIENT_ID',
|
||||
clientSecret: 'TEST_CLIENT_SECRET',
|
||||
passReqToCallback: true
|
||||
};
|
||||
|
||||
const verify: VerifyFunction = (accessToken: string, refreshToken: string, profile: Profile, done: (err: any, user?: any, info?: any) => void) => {
|
||||
const verify: PassportFacebookToken.VerifyFunction =
|
||||
(accessToken: string, refreshToken: string, profile: PassportFacebookToken.Profile, done: (err: any, user?: any, info?: any) => void) => {
|
||||
User.findOrCreate(profile.id, profile.provider, (err, user) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
@@ -30,7 +29,8 @@ const verify: VerifyFunction = (accessToken: string, refreshToken: string, profi
|
||||
});
|
||||
};
|
||||
|
||||
const verifyWithRequest: VerifyFunctionWithRequest = (req: express.Request, accessToken: string, refreshToken: string, profile: Profile, done: (err: any, user?: any, info?: any) => void) => {
|
||||
const verifyWithRequest: PassportFacebookToken.VerifyFunctionWithRequest =
|
||||
(req: express.Request, accessToken: string, refreshToken: string, profile: PassportFacebookToken.Profile, done: (err: any, user?: any, info?: any) => void) => {
|
||||
User.findOrCreate(profile.id, profile.provider, (err, user) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
@@ -39,5 +39,5 @@ const verifyWithRequest: VerifyFunctionWithRequest = (req: express.Request, acce
|
||||
});
|
||||
};
|
||||
|
||||
passport.use(new FacebookStrategy(options, verify));
|
||||
passport.use(new FacebookStrategy(optionsWithRequest, verifyWithRequest));
|
||||
passport.use(new PassportFacebookToken(options, verify));
|
||||
passport.use(new PassportFacebookToken(optionsWithRequest, verifyWithRequest));
|
||||
|
||||
Reference in New Issue
Block a user