From 3bf10e44d143f27b549986d617f37def4c7530ba Mon Sep 17 00:00:00 2001 From: Josh Heyse Date: Wed, 3 Jun 2015 11:57:24 -0500 Subject: [PATCH] added passport-google-oauth definitions --- .../passport-google-oauth-tests.ts | 38 ++++++++++++ .../passport-google-oauth.d.ts | 60 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 passport-google-oauth/passport-google-oauth-tests.ts create mode 100644 passport-google-oauth/passport-google-oauth.d.ts diff --git a/passport-google-oauth/passport-google-oauth-tests.ts b/passport-google-oauth/passport-google-oauth-tests.ts new file mode 100644 index 000000000..60fad97b4 --- /dev/null +++ b/passport-google-oauth/passport-google-oauth-tests.ts @@ -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); + }); + }) +); diff --git a/passport-google-oauth/passport-google-oauth.d.ts b/passport-google-oauth/passport-google-oauth.d.ts new file mode 100644 index 000000000..ea6c1e91a --- /dev/null +++ b/passport-google-oauth/passport-google-oauth.d.ts @@ -0,0 +1,60 @@ +// Type definitions for passport-facebook 1.0.3 +// Project: https://github.com/jaredhanson/passport-facebook +// Definitions by: James Roland Cabresos +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +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; + } +}