Type definitions for Passport-GitHub (2)

This commit is contained in:
Maarten Mulders 2017-08-15 15:49:16 +02:00
parent d4f42ab007
commit d57c207a00
4 changed files with 101 additions and 0 deletions

36
types/passport-github2/index.d.ts vendored Normal file
View File

@ -0,0 +1,36 @@
// Type definitions for passport-github 1.1
// Project: https://github.com/jaredhanson/passport-github
// Definitions by: Yasunori Ohoka <https://github.com/yasupeke>
// Maarten Mulders <https://github.com/mthmulders/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
import passport = require('passport');
import express = require('express');
export interface Profile extends passport.Profile {
profileUrl: string;
}
export interface StrategyOption {
clientID: string;
clientSecret: string;
callbackURL: string;
scope?: string[];
userAgent?: string;
authorizationURL?: string;
tokenURL?: string;
scopeSeparator?: string;
customHeaders?: string;
userProfileURL?: string;
}
export class Strategy implements passport.Strategy {
constructor(options: StrategyOption, verify: (accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any) => void) => void);
userProfile: (accessToken: string, done?: (error: any, profile: Profile) => void) => void;
name: string;
authenticate: (req: express.Request, options?: passport.AuthenticateOptions) => void;
}

View File

@ -0,0 +1,42 @@
/**
* Created by jcabresos on 4/19/2014.
*/
import passport = require('passport');
import github = require('passport-github2');
// just some test model
const User = {
findOrCreate(id: string, provider: string, callback: (err: any, user: any) => void): void {
callback(null, { username: 'james' });
}
};
const callbackURL = process.env.PASSPORT_GITHUB_CALLBACK_URL;
const clientID = process.env.PASSPORT_GITHUB_CONSUMER_KEY;
const clientSecret = process.env.PASSPORT_GITHUB_CONSUMER_SECRET;
if (typeof callbackURL === "undefined") {
throw new Error("callbackURL is undefined");
}
if (typeof clientID === "undefined") {
throw new Error("clientID is undefined");
}
if (typeof clientSecret === "undefined") {
throw new Error("clientSecret is undefined");
}
passport.use(new github.Strategy(
{
callbackURL,
clientID,
clientSecret
},
(accessToken: string, refreshToken: string, profile: github.Profile, done: (error: any, user?: any) => void) => {
User.findOrCreate(profile.id, profile.provider, (err, user) => {
if (err) { return done(err); }
done(null, user);
});
})
);

View File

@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"passport-github2-tests.ts"
]
}

View File

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