fix missing protected _oauth2 property

This commit is contained in:
Wang Zishi
2018-05-14 10:46:43 +08:00
parent 3a870ec70a
commit 626ba446b8
2 changed files with 17 additions and 2 deletions

View File

@@ -1,15 +1,24 @@
// Type definitions for passport-oauth2 1.4
// Project: https://github.com/jaredhanson/passport-oauth2#readme
// Definitions by: Pasi Eronen <https://github.com/pasieronen>
// Wang Zishi <https://github.com/WangZishi>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import { Request } from 'express';
import { Strategy } from 'passport';
import { OAuth2 } from 'oauth';
declare class OAuth2Strategy extends Strategy {
name: string;
/**
* NOTE: The _oauth2 property is considered "protected". Subclasses are
* allowed to use it when making protected resource requests to retrieve
* the user profile.
*/
protected _oauth2: OAuth2;
constructor(options: OAuth2Strategy.StrategyOptions, verify: OAuth2Strategy.VerifyFunction);
constructor(options: OAuth2Strategy.StrategyOptionsWithRequest, verify: OAuth2Strategy.VerifyFunctionWithRequest);

View File

@@ -24,11 +24,11 @@ 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) {
verifyCallback(undefined, {userid: '1'});
verifyCallback(undefined, { userid: '1' });
}
function verifyFunction4(_req: Request, _accessToken: string, _refreshToken: string, _results: any, _profile: any, verifyCallback: VerifyCallback) {
verifyCallback(undefined, {userid: '1'});
verifyCallback(undefined, { userid: '1' });
}
const strategyOptions2: StrategyOptionsWithRequest = {
@@ -49,3 +49,9 @@ const err1 = new AuthorizationError('Description', 'invalid_request', undefined)
const err2 = new TokenError(undefined, 'invalid_request', undefined);
const err3 = new InternalOAuthError('Hello', {});
class MyStrategy extends OAuth2Strategy {
useProtectedMethod() {
this._oauth2.get('http://www.example.com/profile', 'token', 'http://www.example.com/callback');
}
}