added passport-google-oauth definitions

This commit is contained in:
Josh Heyse
2015-06-03 11:57:24 -05:00
parent 265b807686
commit 3bf10e44d1
2 changed files with 98 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
/**
* Created by jcabresos on 4/19/2014.
*/
import passport = require('passport');
import google = require('passport-google-oauth');
// just some test model
var User = {
findOrCreate(id:string, provider:string, callback:(err:any, user:any) => void): void {
callback(null, {username:'james'});
}
}
passport.use(new google.OAuthStrategy({
consumerKey: process.env.GOOGLE_CONSUMER_KEY,
consumerSecret: process.env.GOOGLE_CONSUMER_SECRET,
callbackURL: process.env.PASSPORT_GOOGLE_CALLBACK_URL
},
function(accessToken:string, refreshToken:string, profile:google.Profile, done:(error:any, user?:any) => void) {
User.findOrCreate(profile.id, profile.provider, function(err, user) {
if (err) { return done(err); }
done(null, user);
});
})
);
passport.use(new google.OAuth2Strategy({
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: process.env.PASSPORT_GOOGLE_CALLBACK_URL
},
function(accessToken:string, refreshToken:string, profile:google.Profile, done:(error:any, user?:any) => void) {
User.findOrCreate(profile.id, profile.provider, function(err, user) {
if (err) { return done(err); }
done(null, user);
});
})
);

View File

@@ -0,0 +1,60 @@
// Type definitions for passport-facebook 1.0.3
// Project: https://github.com/jaredhanson/passport-facebook
// Definitions by: James Roland Cabresos <https://github.com/staticfunction>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../passport/passport.d.ts"/>
declare module 'passport-google-oauth' {
import passport = require('passport');
import express = require('express');
interface Profile extends passport.Profile {
gender: string;
}
interface IOAuthStrategyOption {
consumerKey: string;
consumerSecret: string;
callbackURL: string;
reguestTokenURL?: string;
accessTokenURL?: string;
userAuthorizationURL?: string;
sessionKey?: string;
}
class OAuthStrategy implements passport.Strategy {
constructor(options: IOAuthStrategyOption,
verify: (accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any) => void) => void);
name: string;
authenticate: (req: express.Request, options?: Object) => void;
}
interface IOAuth2StrategyOption {
clientID: string;
clientSecret: string;
callbackURL: string;
authorizationURL?: string;
tokenURL?: string;
accessType?: string;
approval_prompt?: string;
prompt?: string;
loginHint?: string;
userID?: string;
hostedDomain?: string;
display?: string;
requestVisibleActions?: string;
openIDRealm?: string;
}
class OAuth2Strategy implements passport.Strategy {
constructor(options: IOAuth2StrategyOption,
verify: (accessToken: string, refreshToken: string, profile: Profile, done: (error: any, user?: any) => void) => void);
name: string;
authenticate: (req: express.Request, options?: Object) => void;
}
}