diff --git a/types/passport-google-oauth2/index.d.ts b/types/passport-google-oauth2/index.d.ts new file mode 100644 index 0000000000..5c131622e7 --- /dev/null +++ b/types/passport-google-oauth2/index.d.ts @@ -0,0 +1,48 @@ +// Type definitions for passport-google-oauth2 0.1 +// Project: https://github.com/mstade/passport-google-oauth2 +// Definitions by: Elliot Blackburn +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import {Request} from 'express'; + +export interface StrategyOptions { + clientID: string; + clientSecret: string; + callbackURL: string; + passReqToCallback?: true; + scope?: string[]; +} + +export interface StrategyOptionsWithRequest { + clientID: string; + clientSecret: string; + callbackURL: string; + passReqToCallback: true; + scope?: string[]; +} + +export interface VerifyOptions { + message: string; +} + +export type VerifyCallback = (error: any, user?: any, options?: VerifyOptions) => void; + +export type VerifyFunctionWithRequest = ( + req: Request, + accessToken: string, + refreshToken: string, + profile: any, + done: VerifyCallback +) => void; + +export type VerifyFunction = (accessToken: string, refreshToken: string, profile: any, done: VerifyCallback) => void; + +export class Strategy implements Strategy { + name: string; + authenticate: (req: Request, options?: object) => void; + + constructor(options: StrategyOptionsWithRequest, verify: VerifyFunctionWithRequest); + constructor(options: StrategyOptions, verify: VerifyFunction); + constructor(verify: VerifyFunction); +} diff --git a/types/passport-google-oauth2/passport-google-oauth2-tests.ts b/types/passport-google-oauth2/passport-google-oauth2-tests.ts new file mode 100644 index 0000000000..37261bc818 --- /dev/null +++ b/types/passport-google-oauth2/passport-google-oauth2-tests.ts @@ -0,0 +1,17 @@ +import * as express from 'express'; +import * as PassportGoogle from 'passport-google-oauth2'; +import { Strategy as GoogleStrategy } from 'passport-google-oauth2'; + +new GoogleStrategy({ + callbackURL: 'callbackurl', + clientID: 'clientid', + clientSecret: 'shhh', + passReqToCallback: true, +}, ( + req: express.Request, + accessToken: string, + refreshToken: string, + profile: any, + done: PassportGoogle.VerifyCallback) => { + // Some registration / log in logic +}); diff --git a/types/passport-google-oauth2/tsconfig.json b/types/passport-google-oauth2/tsconfig.json new file mode 100644 index 0000000000..38b1a17f54 --- /dev/null +++ b/types/passport-google-oauth2/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "passport-google-oauth2-tests.ts" + ] +} diff --git a/types/passport-google-oauth2/tslint.json b/types/passport-google-oauth2/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/passport-google-oauth2/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }