mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-25 13:45:48 +08:00
Add type declarations for 'passport-vkontakte'
This commit is contained in:
61
types/passport-vkontakte/index.d.ts
vendored
Normal file
61
types/passport-vkontakte/index.d.ts
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
// Type definitions for passport-vkontakte 1.3
|
||||
// Project: https://github.com/stevebest/passport-vkontakte#readme
|
||||
// Definitions by: Anton Lobashev <https://github.com/soulthreads>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
import * as passport from 'passport';
|
||||
import * as express from 'express';
|
||||
|
||||
export interface Profile extends passport.Profile {
|
||||
gender?: string;
|
||||
profileUrl?: string;
|
||||
|
||||
_raw: string;
|
||||
_json: any;
|
||||
}
|
||||
|
||||
export interface StrategyOptions {
|
||||
clientID: string;
|
||||
clientSecret: string;
|
||||
callbackURL: string;
|
||||
|
||||
profileFields?: string[];
|
||||
apiVersion?: string;
|
||||
|
||||
lang?: string;
|
||||
}
|
||||
|
||||
export type VerifyCallback = (error: any, user?: any, info?: any) => void;
|
||||
|
||||
export interface Params {
|
||||
accessToken: string;
|
||||
email?: string;
|
||||
expires_in: number;
|
||||
user_id: number;
|
||||
}
|
||||
|
||||
export type VerifyFunctionWithParams = (
|
||||
accessToken: string,
|
||||
refreshToken: string,
|
||||
params: Params,
|
||||
profile: Profile,
|
||||
done: VerifyCallback
|
||||
) => void;
|
||||
|
||||
export type VerifyFunction = (
|
||||
accessToken: string,
|
||||
refreshToken: string,
|
||||
profile: Profile,
|
||||
done: VerifyCallback
|
||||
) => void;
|
||||
|
||||
export class Strategy implements passport.Strategy {
|
||||
constructor(
|
||||
options: StrategyOptions,
|
||||
verify: VerifyFunctionWithParams | VerifyFunction
|
||||
);
|
||||
|
||||
name: string;
|
||||
authenticate: (req: express.Request, options?: object) => void;
|
||||
}
|
||||
50
types/passport-vkontakte/passport-vkontakte-tests.ts
Normal file
50
types/passport-vkontakte/passport-vkontakte-tests.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import * as passport from 'passport';
|
||||
import vk = require('passport-vkontakte');
|
||||
|
||||
const User = {
|
||||
findOrCreate(
|
||||
id: string,
|
||||
provider: string,
|
||||
callback: (err: any, user: any) => void
|
||||
): void {
|
||||
callback(null, { username: 'ivan' });
|
||||
}
|
||||
};
|
||||
|
||||
const options: vk.StrategyOptions = {
|
||||
clientID: 'PASSPORT_VKONTAKTE_CLIENT_ID',
|
||||
clientSecret: 'PASSPORT_VKONTAKTE_CLIENT_SECRET',
|
||||
callbackURL: 'PASSPORT_VKONTAKTE_CALLBACK_URL'
|
||||
};
|
||||
|
||||
const verify: vk.VerifyFunction = (
|
||||
accessToken: string,
|
||||
refreshToken: string,
|
||||
profile: vk.Profile,
|
||||
done: vk.VerifyCallback
|
||||
) => {
|
||||
User.findOrCreate(profile.id, profile.provider, (err, user) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
}
|
||||
done(null, user);
|
||||
});
|
||||
};
|
||||
|
||||
const verifyWithParams: vk.VerifyFunctionWithParams = (
|
||||
accessToken: string,
|
||||
refreshToken: string,
|
||||
params: vk.Params,
|
||||
profile: vk.Profile,
|
||||
done: vk.VerifyCallback
|
||||
) => {
|
||||
User.findOrCreate(profile.id, profile.provider, (err, user) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
}
|
||||
done(null, user);
|
||||
});
|
||||
};
|
||||
|
||||
passport.use(new vk.Strategy(options, verify));
|
||||
passport.use(new vk.Strategy(options, verifyWithParams));
|
||||
23
types/passport-vkontakte/tsconfig.json
Normal file
23
types/passport-vkontakte/tsconfig.json
Normal file
@@ -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-vkontakte-tests.ts"
|
||||
]
|
||||
}
|
||||
3
types/passport-vkontakte/tslint.json
Normal file
3
types/passport-vkontakte/tslint.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user