mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 15:57:13 +00:00
add passport-ouath2-client-password
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
// Type definitions for passport-oauth2-client-password 0.1.2
|
||||
// Project: https://github.com/jaredhanson/passport-oauth2-client-password
|
||||
// Definitions by: Ivan Zubok <https://github.com/akaNightmare>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="passport"/>
|
||||
/// <reference types="express"/>
|
||||
|
||||
import passport = require('passport');
|
||||
import express = require('express');
|
||||
|
||||
interface StrategyOptionsWithRequestInterface {
|
||||
passReqToCallback: boolean;
|
||||
}
|
||||
|
||||
interface VerifyFunctionWithRequest {
|
||||
(req: express.Request, clientId: string, clientSecret: string, done: (error: any, client?: any, info?: any) => void): void;
|
||||
}
|
||||
|
||||
interface VerifyFunction {
|
||||
(clientId: string, clientSecret: string, done: (error: any, client?: any, info?: any) => void): void;
|
||||
}
|
||||
|
||||
declare class Strategy implements passport.Strategy {
|
||||
constructor(options: StrategyOptionsWithRequestInterface, verify: VerifyFunctionWithRequest);
|
||||
constructor(verify: VerifyFunction);
|
||||
|
||||
name: string;
|
||||
authenticate: (req: express.Request, options?: Object) => void;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Created by Ivan Zubok <https://github.com/akaNightmare>.
|
||||
*/
|
||||
|
||||
import express = require('../express');
|
||||
import passport = require('passport');
|
||||
import oauth2ClientPassword = require('passport-oauth2-client-password');
|
||||
|
||||
//#region Test Models
|
||||
interface IClient {
|
||||
clientId: string;
|
||||
clientSecret: string;
|
||||
}
|
||||
|
||||
class Client implements IClient {
|
||||
public clientId: string;
|
||||
public clientSecret: string;
|
||||
|
||||
static findOne(client: IClient, callback: (err: Error, client: Client) => void): void {
|
||||
callback(null, new this);
|
||||
}
|
||||
}
|
||||
//#endregion
|
||||
|
||||
passport.use(new oauth2ClientPassword.Strategy((clientId: string, clientSecret: string, done: any) => {
|
||||
Client.findOne({clientId, clientSecret}, function(err, client) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
if (!client) {
|
||||
return done(null, false);
|
||||
}
|
||||
|
||||
return done(null, client);
|
||||
});
|
||||
}));
|
||||
|
||||
passport.use(new oauth2ClientPassword.Strategy({
|
||||
passReqToCallback: false
|
||||
}, function(req: express.Request, clientId: string, clientSecret: string, done: any) {
|
||||
Client.findOne({clientId, clientSecret}, function(err, client) {
|
||||
if (err) {
|
||||
return done(err, null, { message: 'Access Denied' });
|
||||
}
|
||||
|
||||
if (!client) {
|
||||
return done(null, false, 'Access Denied');
|
||||
}
|
||||
|
||||
return done(null, client);
|
||||
});
|
||||
}));
|
||||
|
||||
let app = express();
|
||||
app.post('/login', passport.authenticate('oauth2-client-password'), function (req: express.Request, res: express.Response) {
|
||||
res.redirect('/');
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"passport-oauth2-client-password-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Reference in New Issue
Block a user