mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-13 21:40:21 +00:00
Add missing strategy options to StrategyOptionsBase typing (#43674)
* Add missing strategy options to StrategyOptionsBase typing * Add contribution notes * Change test
This commit is contained in:
Vendored
+4
@@ -4,6 +4,7 @@
|
||||
// Wang Zishi <https://github.com/WangZishi>
|
||||
// Eduardo AC <https://github.com/EduardoAC>
|
||||
// Ivan Fernandes <https://github.com/ivan94>
|
||||
// Daphne Smit <https://github.com/daphnesmit>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
@@ -72,6 +73,9 @@ declare namespace OAuth2Strategy {
|
||||
sessionKey?: string;
|
||||
store?: StateStore;
|
||||
state?: any;
|
||||
skipUserProfile?: any;
|
||||
pkce?: boolean;
|
||||
proxy?: any;
|
||||
}
|
||||
interface StrategyOptions extends _StrategyOptionsBase {
|
||||
passReqToCallback?: false;
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
import OAuth2Strategy = require('passport-oauth2');
|
||||
import { Strategy, StrategyOptions, StrategyOptionsWithRequest, VerifyCallback, AuthorizationError, TokenError,
|
||||
InternalOAuthError, Metadata, StateStore, StateStoreStoreCallback, StateStoreVerifyCallback } 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';
|
||||
|
||||
@@ -9,14 +20,20 @@ const strategyOptions1: StrategyOptions = {
|
||||
callbackURL: 'http://www.example.com/callback',
|
||||
clientID: 'dummy',
|
||||
clientSecret: 'secret',
|
||||
tokenURL: 'http://www.example.com/token'
|
||||
tokenURL: 'http://www.example.com/token',
|
||||
};
|
||||
|
||||
function verifyFunction1(_accessToken: string, _refreshToken: string, _profile: any, verifyCallback: VerifyCallback) {
|
||||
verifyCallback(new Error('unimplemented'));
|
||||
}
|
||||
|
||||
function verifyFunction2(_accessToken: string, _refreshToken: string, _results: any, _profile: any, verifyCallback: VerifyCallback) {
|
||||
function verifyFunction2(
|
||||
_accessToken: string,
|
||||
_refreshToken: string,
|
||||
_results: any,
|
||||
_profile: any,
|
||||
verifyCallback: VerifyCallback,
|
||||
) {
|
||||
verifyCallback(new Error('unimplemented'));
|
||||
}
|
||||
|
||||
@@ -24,11 +41,24 @@ const strategy1: OAuth2Strategy = new OAuth2Strategy(strategyOptions1, verifyFun
|
||||
|
||||
const strategy2: Strategy = new OAuth2Strategy(strategyOptions1, verifyFunction2);
|
||||
|
||||
function verifyFunction3(_req: Request, _accessToken: string, _refreshToken: string, _profile: any, verifyCallback: VerifyCallback) {
|
||||
function verifyFunction3(
|
||||
_req: Request,
|
||||
_accessToken: string,
|
||||
_refreshToken: string,
|
||||
_profile: any,
|
||||
verifyCallback: VerifyCallback,
|
||||
) {
|
||||
verifyCallback(undefined, { userid: '1' });
|
||||
}
|
||||
|
||||
function verifyFunction4(_req: Request, _accessToken: string, _refreshToken: string, _results: any, _profile: any, verifyCallback: VerifyCallback) {
|
||||
function verifyFunction4(
|
||||
_req: Request,
|
||||
_accessToken: string,
|
||||
_refreshToken: string,
|
||||
_results: any,
|
||||
_profile: any,
|
||||
verifyCallback: VerifyCallback,
|
||||
) {
|
||||
verifyCallback(undefined, { userid: '1' });
|
||||
}
|
||||
|
||||
@@ -37,7 +67,7 @@ const strategyOptions2: StrategyOptionsWithRequest = {
|
||||
clientID: 'dummy',
|
||||
clientSecret: 'secret',
|
||||
tokenURL: 'http://www.example.com/token',
|
||||
passReqToCallback: true
|
||||
passReqToCallback: true,
|
||||
};
|
||||
|
||||
const strategy3: PassportStrategy = new OAuth2Strategy(strategyOptions2, verifyFunction3);
|
||||
@@ -61,12 +91,17 @@ class MyStrategy extends OAuth2Strategy {
|
||||
const metadata: Metadata = {
|
||||
authorizationURL: 'http://www.example.com/auth',
|
||||
clientID: 'dummy',
|
||||
tokenURL: 'http://www.example.com/token'
|
||||
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 {}
|
||||
verify(
|
||||
req: Request,
|
||||
state: string,
|
||||
meta: StateStoreVerifyCallback | Metadata,
|
||||
callback?: StateStoreVerifyCallback,
|
||||
): void {}
|
||||
}
|
||||
|
||||
const myStore = new MyStore();
|
||||
@@ -78,13 +113,15 @@ const strategyOptions3: StrategyOptions = {
|
||||
tokenURL: 'http://www.example.com/token',
|
||||
callbackURL: 'http://www.example.com/callback',
|
||||
customHeaders: {
|
||||
'content-type': 'text/html'
|
||||
'content-type': 'text/html',
|
||||
},
|
||||
scope: ['scope1', 'scope2'],
|
||||
scopeSeparator: ' ',
|
||||
sessionKey: 'oauth',
|
||||
state: {id: 1},
|
||||
store: myStore
|
||||
state: { id: 1 },
|
||||
store: myStore,
|
||||
skipUserProfile: true,
|
||||
pkce: false,
|
||||
};
|
||||
|
||||
const strategy5: Strategy = new Strategy(strategyOptions3, verifyFunction2);
|
||||
|
||||
Reference in New Issue
Block a user