diff --git a/types/passport-github/index.d.ts b/types/passport-github/index.d.ts index 4eaa13e359..9cd6329e62 100644 --- a/types/passport-github/index.d.ts +++ b/types/passport-github/index.d.ts @@ -5,48 +5,73 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 -import passport = require('passport'); -import express = require('express'); -import OAuth2 = require('passport-oauth2'); +import * as passport from 'passport'; +import * as express from 'express'; +import * as oauth2 from 'passport-oauth2'; import { OutgoingHttpHeaders } from 'http'; -export interface Profile extends passport.Profile { - profileUrl: string; +import github = Strategy; + +declare class Strategy extends oauth2.Strategy { + constructor(options: github.StrategyOptions, verify: (accessToken: string, refreshToken: string, profile: github.Profile, done: oauth2.VerifyCallback) => void); + // NOTE: A union of function types prevents contextual typing of arguments. + // tslint:disable-next-line:unified-signatures + constructor(options: github.StrategyOptions, verify: (accessToken: string, refreshToken: string, params: any, profile: github.Profile, done: oauth2.VerifyCallback) => void); + constructor(options: github.StrategyOptionsWithRequest, verify: (req: express.Request, accessToken: string, refreshToken: string, profile: github.Profile, done: oauth2.VerifyCallback) => void); + // NOTE: A union of function types prevents contextual typing of arguments. + // tslint:disable-next-line:unified-signatures max-line-length + constructor(options: github.StrategyOptionsWithRequest, verify: (req: express.Request, accessToken: string, params: any, refreshToken: string, profile: github.Profile, done: oauth2.VerifyCallback) => void); } -export interface StrategyOptionBase { - clientID: string; - clientSecret: string; - callbackURL: string; +declare namespace Strategy { + // NOTE: not true for `export import` statements + // tslint:disable-next-line:strict-export-declare-modifiers + export import Strategy = github; - scope?: string[]; - userAgent?: string; - state?: string; + interface _StrategyOptionsBase { + authorizationURL?: string; + tokenURL?: string; + clientID: string; + clientSecret: string; + callbackURL?: string; + customHeaders?: OutgoingHttpHeaders; + scope?: string | string[]; + scopeSeparator?: string; + sessionKey?: string; + store?: oauth2.StateStore; + state?: string; + userAgent?: string; + userProfileURL?: string; + } - authorizationURL?: string; - tokenURL?: string; - scopeSeparator?: string; - customHeaders?: OutgoingHttpHeaders; - userProfileURL?: string; + interface StrategyOptions extends _StrategyOptionsBase { + passReqToCallback?: false; + } + + interface StrategyOptionsWithRequest extends _StrategyOptionsBase { + passReqToCallback: true; + } + + interface Profile extends passport.Profile { + provider: "github"; + profileUrl: string; + _raw: string; + _json: object; + } + + /** @deprecated Types renamed for consistency with 'passport-oauth2'. Use `_StrategyOptionsBase` instead. */ + type StrategyOptionBase = _StrategyOptionsBase; + + /** @deprecated Types renamed for consistency with 'passport-oauth2'. Use `StrategyOptions` instead. */ + type StrategyOption = StrategyOptions; + + /** @deprecated Types renamed for consistency with 'passport-oauth2'. Use `StrategyOptionsWithRequest` instead. */ + type StrategyOptionWithRequest = StrategyOptionsWithRequest; + + type OAuth2StrategyOptionsWithoutRequiredURLs = Pick< + oauth2._StrategyOptionsBase, + Exclude + >; } -export type OAuth2StrategyOptionsWithoutRequiredURLs = Pick< - OAuth2._StrategyOptionsBase, - Exclude ->; - -export interface StrategyOption extends StrategyOptionBase { - passReqToCallback?: false; -} -export interface StrategyOptionWithRequest extends StrategyOptionBase { - passReqToCallback: true; -} - -export class Strategy extends passport.Strategy { - constructor(options: StrategyOption, verify: (accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any) => void) => void); - constructor(options: StrategyOptionWithRequest, verify: (req: express.Request, accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any) => void) => void); - userProfile: (accessToken: string, done?: (error: any, profile: Profile) => void) => void; - - name: string; - authenticate(req: express.Request, options?: passport.AuthenticateOptions): void; -} +export = Strategy;