Improve typings for passport-github (#34835)

This commit is contained in:
Ron Buckton
2019-04-26 15:22:35 -07:00
committed by Pranav Senthilnathan
parent 299d9481f3
commit 39e7075075

View File

@@ -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<keyof oauth2._StrategyOptionsBase, 'authorizationURL' | 'tokenURL'>
>;
}
export type OAuth2StrategyOptionsWithoutRequiredURLs = Pick<
OAuth2._StrategyOptionsBase,
Exclude<keyof OAuth2._StrategyOptionsBase, 'authorizationURL' | 'tokenURL'>
>;
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;