mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-27 12:20:19 +00:00
Merge pull request #30981 from ivan94/passport-bnet
Type definitions for passport-bnet
This commit is contained in:
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
// Type definitions for passport-bnet 2.0
|
||||
// Project: https://github.com/Blizzard/passport-bnet#readme
|
||||
// Definitions by: Ivan Fernandes <https://github.com/ivan94>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
import { Strategy as OAuth2Strategy, VerifyFunction, VerifyFunctionWithRequest } from 'passport-oauth2';
|
||||
|
||||
declare class BnetStrategy extends OAuth2Strategy {
|
||||
constructor(options: BnetStrategy.StrategyOptions, verify: VerifyFunction);
|
||||
constructor(options: BnetStrategy.StrategyOptionsWithRequest, verify: VerifyFunctionWithRequest);
|
||||
}
|
||||
|
||||
declare namespace BnetStrategy {
|
||||
interface _BaseBnetOptions {
|
||||
region?: string;
|
||||
|
||||
scopeSeparator?: string;
|
||||
customHeaders?: object;
|
||||
authorizationURL?: string;
|
||||
tokenURL?: string;
|
||||
scope?: string;
|
||||
clientID: string;
|
||||
clientSecret: string;
|
||||
callbackURL?: string;
|
||||
}
|
||||
|
||||
interface StrategyOptions extends _BaseBnetOptions {
|
||||
passReqToCallback?: false;
|
||||
}
|
||||
|
||||
interface StrategyOptionsWithRequest extends _BaseBnetOptions {
|
||||
passReqToCallback: true;
|
||||
}
|
||||
|
||||
function getHost(region: string): string;
|
||||
|
||||
type Strategy = BnetStrategy;
|
||||
const Strategy: typeof BnetStrategy;
|
||||
}
|
||||
|
||||
export = BnetStrategy;
|
||||
@@ -0,0 +1,64 @@
|
||||
// Based on passport-oauth2/passport-oauth2-tests.ts
|
||||
|
||||
import BnetStrategy = require("passport-bnet");
|
||||
import { Strategy, StrategyOptions, StrategyOptionsWithRequest } from "passport-bnet";
|
||||
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: ' ',
|
||||
customHeaders: {}
|
||||
};
|
||||
|
||||
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) {
|
||||
verifyCallback(new Error('unimplemented'));
|
||||
}
|
||||
|
||||
const strategy1: BnetStrategy = new BnetStrategy(strategyOptions1, verifyFunction1);
|
||||
|
||||
const strategy2: Strategy = new BnetStrategy(strategyOptions1, verifyFunction2);
|
||||
|
||||
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) {
|
||||
verifyCallback(undefined, { userid: '1' });
|
||||
}
|
||||
|
||||
const strategyOptions2: StrategyOptionsWithRequest = {
|
||||
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: ' ',
|
||||
customHeaders: {},
|
||||
passReqToCallback: true
|
||||
};
|
||||
|
||||
const strategy3: OAuth2Strategy = new BnetStrategy
|
||||
(strategyOptions2, verifyFunction3);
|
||||
|
||||
const strategy4: Strategy = new Strategy(strategyOptions2, verifyFunction4);
|
||||
|
||||
class MyStrategy extends BnetStrategy {
|
||||
useProtectedProperty() {
|
||||
this._oauth2.get('http://www.example.com/profile', 'token', err => err.statusCode);
|
||||
this._oauth2.get('http://www.example.com/profile', 'token', (err, result) => result);
|
||||
this._oauth2.get('http://www.example.com/profile', 'token', (err, result, response) => response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"passport-bnet-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user