mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
Added types for passport-facebook-token
This commit is contained in:
+49
-29
@@ -1,38 +1,58 @@
|
||||
// Type definitions for passport-facebook-token 0.4.0
|
||||
// Type definitions for passport-facebook-token 0.4
|
||||
// Project: https://github.com/drudge/passport-facebook-token
|
||||
// Definitions by: Ray Martone <https://github.com/rmartone>
|
||||
// Definitions by: Ray Martone <https://github.com/rmartone>, Michael Randolph <https://github.com/mrand01>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="passport"/>
|
||||
|
||||
|
||||
|
||||
import passport = require('passport');
|
||||
import express = require('express');
|
||||
|
||||
interface Profile extends passport.Profile {
|
||||
gender: string;
|
||||
profileUrl: string;
|
||||
}
|
||||
|
||||
interface StrategyOptions {
|
||||
clientID: string;
|
||||
clientSecret: string;
|
||||
authorizationURL?: string;
|
||||
tokenURL?: string;
|
||||
scopeSeparator?: string;
|
||||
passReqToCallback?: Function;
|
||||
enableProof?: boolean;
|
||||
profileFields?: any[];
|
||||
}
|
||||
import * as passport from 'passport';
|
||||
import * as express from 'express';
|
||||
|
||||
declare class Strategy implements passport.Strategy {
|
||||
constructor(options: StrategyOptions,
|
||||
verify: (accessToken: string,
|
||||
refreshToken: string,
|
||||
profile: Profile,
|
||||
done: (err: any, user?: any) => void) => void);
|
||||
constructor(options: Strategy.StrategyOptionsWithRequest, verify: Strategy.VerifyFunctionWithRequest)
|
||||
constructor(options: Strategy.StrategyOptions, verify: Strategy.VerifyFunction);
|
||||
|
||||
name: string;
|
||||
authenticate: (req: express.Request, options?: any) => void;
|
||||
}
|
||||
|
||||
declare namespace Strategy {
|
||||
interface ValueObject {
|
||||
value: string;
|
||||
}
|
||||
|
||||
interface Profile extends passport.Profile {
|
||||
provider: string;
|
||||
id: string;
|
||||
displayName: string;
|
||||
name: {
|
||||
familyName: string;
|
||||
givenName: string;
|
||||
middleName: string;
|
||||
};
|
||||
gender: string;
|
||||
emails: ValueObject[];
|
||||
photos: ValueObject[];
|
||||
_raw: string;
|
||||
_json: any;
|
||||
}
|
||||
|
||||
interface StrategyOptions {
|
||||
clientID: string;
|
||||
clientSecret: string;
|
||||
authorizationURL?: string;
|
||||
tokenURL?: string;
|
||||
scopeSeparator?: string;
|
||||
enableProof?: boolean;
|
||||
profileFields?: string[];
|
||||
}
|
||||
|
||||
interface StrategyOptionsWithRequest extends StrategyOptions {
|
||||
passReqToCallback: true;
|
||||
}
|
||||
|
||||
type VerifyFunction = (accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any, info?: any) => void) => void;
|
||||
|
||||
type VerifyFunctionWithRequest = (req: express.Request, accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any, info?: any) => void) => void;
|
||||
}
|
||||
|
||||
export = Strategy;
|
||||
|
||||
@@ -1,28 +1,43 @@
|
||||
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 passport = require('passport');
|
||||
import facebook = require('passport-facebook-token');
|
||||
|
||||
var User = {
|
||||
const User = {
|
||||
findOrCreate(id: string, provider: string, callback: (err: any, user: any) => void): void {
|
||||
callback(null, {username: 'ray'});
|
||||
callback(null, { username: 'ray' });
|
||||
}
|
||||
}
|
||||
|
||||
var options: facebook.StrategyOptions = {
|
||||
clientID: process.env.PASSPORT_FACEBOOK_CLIENT_ID,
|
||||
clientSecret: process.env.PASSPORT_FACEBOOK_CLIENT_SECRET
|
||||
};
|
||||
|
||||
function verify(accessToken: string,
|
||||
refreshToken: string,
|
||||
profile: facebook.Profile,
|
||||
done: (err: any, user?: any) => void) {
|
||||
User.findOrCreate(profile.id, profile.provider, function (err, user) {
|
||||
const options: StrategyOptions = {
|
||||
clientID: 'TEST_CLIENT_ID',
|
||||
clientSecret: 'TEST_CLIENT_SECRET'
|
||||
};
|
||||
|
||||
const optionsWithRequest: 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) => {
|
||||
User.findOrCreate(profile.id, profile.provider, (err, user) => {
|
||||
if (err) {
|
||||
return done(err);
|
||||
done(err);
|
||||
}
|
||||
done(null, user);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
passport.use(new facebook.Strategy(options, verify));
|
||||
const verifyWithRequest: VerifyFunctionWithRequest = (req: express.Request, accessToken: string, refreshToken: string, profile: Profile, done: (err: any, user?: any, info?: any) => void) => {
|
||||
User.findOrCreate(profile.id, profile.provider, (err, user) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
}
|
||||
done(null, user);
|
||||
});
|
||||
};
|
||||
|
||||
passport.use(new FacebookStrategy(options, verify));
|
||||
passport.use(new FacebookStrategy(optionsWithRequest, verifyWithRequest));
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
|
||||
@@ -1,79 +1 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
|
||||
Reference in New Issue
Block a user