mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Type definitions for Passport-GitHub (2)
This commit is contained in:
parent
d4f42ab007
commit
d57c207a00
36
types/passport-github2/index.d.ts
vendored
Normal file
36
types/passport-github2/index.d.ts
vendored
Normal 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;
|
||||
}
|
||||
42
types/passport-github2/passport-github2-tests.ts
Normal file
42
types/passport-github2/passport-github2-tests.ts
Normal 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);
|
||||
});
|
||||
})
|
||||
);
|
||||
22
types/passport-github2/tsconfig.json
Normal file
22
types/passport-github2/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/passport-github2/tslint.json
Normal file
1
types/passport-github2/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user