Merge pull request #31063 from ivan94/passport-type-fixes

Added missing options to passport-oauth2 and fixes to passport-bnet and passport-github2
This commit is contained in:
Jesse Trinity
2018-12-10 15:42:57 -08:00
committed by GitHub
5 changed files with 67 additions and 15 deletions
+5 -10
View File
@@ -4,7 +4,7 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import { Strategy as OAuth2Strategy, VerifyFunction, VerifyFunctionWithRequest } from 'passport-oauth2';
import { Strategy as OAuth2Strategy, VerifyFunction, VerifyFunctionWithRequest, _StrategyOptionsBase } from 'passport-oauth2';
declare class BnetStrategy extends OAuth2Strategy {
constructor(options: BnetStrategy.StrategyOptions, verify: VerifyFunction);
@@ -12,17 +12,12 @@ declare class BnetStrategy extends OAuth2Strategy {
}
declare namespace BnetStrategy {
interface _BaseBnetOptions {
region?: string;
scopeSeparator?: string;
customHeaders?: object;
authorizationURL?: string;
tokenURL?: string;
scope?: string;
// passport--bnet accepts any options that passport-oauth2 accepts, but add the option region and makes authorizationURL and tokenURL optional
interface _BaseBnetOptions extends Partial<_StrategyOptionsBase> {
clientID: string;
clientSecret: string;
callbackURL?: string;
region?: string;
}
interface StrategyOptions extends _BaseBnetOptions {
@@ -6,11 +6,9 @@ import { Strategy as OAuth2Strategy, VerifyCallback } from "passport-oauth2";
import { Request } from "express";
const strategyOptions1: StrategyOptions = {
authorizationURL: 'http://www.example.com/auth',
callbackURL: 'http://www.example.com/callback',
clientID: 'dummy',
clientSecret: 'secret',
tokenURL: 'http://www.example.com/token',
region: 'us',
scope: "email",
scopeSeparator: ' ',
+4 -2
View File
@@ -3,12 +3,14 @@
// Definitions by: Yasunori Ohoka <https://github.com/yasupeke>
// Maarten Mulders <https://github.com/mthmulders>
// Christoph Werner <https://github.com/codepunkt>
// Ivan Fernandes <https://github.com/ivan94>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import passport = require('passport');
import oauth2 = require('passport-oauth2');
import express = require('express');
import { OutgoingHttpHeaders } from 'http';
export interface Profile extends passport.Profile {
profileUrl: string;
@@ -25,7 +27,7 @@ export interface StrategyOption extends passport.AuthenticateOptions {
authorizationURL?: string;
tokenURL?: string;
scopeSeparator?: string;
customHeaders?: string;
customHeaders?: OutgoingHttpHeaders;
userProfileURL?: string;
}
@@ -46,7 +48,7 @@ export interface _StrategyOptionsBase extends OAuth2StrategyOptionsWithoutRequir
authorizationURL?: string;
tokenURL?: string;
scopeSeparator?: string;
customHeaders?: string;
customHeaders?: OutgoingHttpHeaders;
userProfileURL?: string;
}
+25
View File
@@ -3,12 +3,14 @@
// Definitions by: Pasi Eronen <https://github.com/pasieronen>
// Wang Zishi <https://github.com/WangZishi>
// Eduardo AC <https://github.com/EduardoAC>
// Ivan Fernandes <https://github.com/ivan94>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import { Request } from 'express';
import { Strategy } from 'passport';
import { OAuth2 } from 'oauth';
import { OutgoingHttpHeaders } from 'http';
declare class OAuth2Strategy extends Strategy {
name: string;
@@ -32,6 +34,23 @@ declare class OAuth2Strategy extends Strategy {
}
declare namespace OAuth2Strategy {
interface Metadata {
authorizationURL: string;
tokenURL: string;
clientID: string;
}
type StateStoreStoreCallback = (err: Error | null, state: any) => void;
type StateStoreVerifyCallback = (err: Error, ok: boolean, state: any) => void;
interface StateStore {
store(req: Request, callback: StateStoreStoreCallback): void;
store(req: Request, meta: Metadata, callback: StateStoreStoreCallback): void;
verify(req: Request, state: string, callback: StateStoreVerifyCallback): void;
verify(req: Request, state: string, meta: Metadata, callback: StateStoreVerifyCallback): void;
}
type VerifyCallback = (err?: Error | null, user?: object, info?: object) => void;
type VerifyFunction =
@@ -47,6 +66,12 @@ declare namespace OAuth2Strategy {
clientID: string;
clientSecret: string;
callbackURL?: string;
customHeaders?: OutgoingHttpHeaders;
scope?: string | string[];
scopeSeparator?: string;
sessionKey?: string;
store?: StateStore;
state?: any;
}
interface StrategyOptions extends _StrategyOptionsBase {
passReqToCallback?: false;
+33 -1
View File
@@ -1,5 +1,6 @@
import OAuth2Strategy = require('passport-oauth2');
import { Strategy, StrategyOptions, StrategyOptionsWithRequest, VerifyCallback, AuthorizationError, TokenError, InternalOAuthError } from 'passport-oauth2';
import { Strategy, StrategyOptions, StrategyOptionsWithRequest, VerifyCallback, AuthorizationError, TokenError,
InternalOAuthError, Metadata, StateStore, StateStoreStoreCallback, StateStoreVerifyCallback } from 'passport-oauth2';
import { Strategy as PassportStrategy } from 'passport';
import { Request } from 'express';
@@ -56,3 +57,34 @@ class MyStrategy extends OAuth2Strategy {
this._oauth2.get('http://www.example.com/profile', 'token', (err, result, response) => response);
}
}
const metadata: Metadata = {
authorizationURL: 'http://www.example.com/auth',
clientID: 'dummy',
tokenURL: 'http://www.example.com/token'
};
class MyStore implements StateStore {
store(req: Request, meta: StateStoreStoreCallback | Metadata, callback?: StateStoreStoreCallback): void {}
verify(req: Request, state: string, meta: StateStoreVerifyCallback | Metadata, callback?: StateStoreVerifyCallback): void {}
}
const myStore = new MyStore();
const strategyOptions3: StrategyOptions = {
authorizationURL: 'http://www.example.com/auth',
clientID: 'dummy',
clientSecret: 'secret',
tokenURL: 'http://www.example.com/token',
callbackURL: 'http://www.example.com/callback',
customHeaders: {
'content-type': 'text/html'
},
scope: ['scope1', 'scope2'],
scopeSeparator: ' ',
sessionKey: 'oauth',
state: {id: 1},
store: myStore
};
const strategy5: Strategy = new Strategy(strategyOptions3, verifyFunction2);