Add type declarations for 'passport-vkontakte'

This commit is contained in:
Anton Lobashev
2018-09-28 15:31:23 +04:00
parent 44ea6863ba
commit 1b36999a19
4 changed files with 137 additions and 0 deletions

61
types/passport-vkontakte/index.d.ts vendored Normal file
View 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;
}

View 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));

View 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"
]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}