steam-login: add types

This commit is contained in:
Nick
2018-08-13 23:42:18 -05:00
parent 7a15941349
commit 6dda163276
4 changed files with 120 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
// Type definitions for steam-login 0.1
// Project: http://github.com/cpancake/steam-login
// Definitions by: Nick Winans <https://github.com/Nicell>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
import { Request, Response, NextFunction } from 'express';
export interface MiddlewareOptions {
verify: string;
realm: string;
apiKey: string;
useSession?: boolean;
}
export interface SteamUser {
_json: {
steamid: string;
personaname: string;
profileurl: string;
avatar: string;
avatarmedium: string;
avatarfull: string;
personastate: number;
communityvisibilitystate: number;
profilestate?: number;
lastlogoff: number;
commentpermission?: number;
realname?: string;
primaryclanid?: string;
timecreated?: number;
gameid?: string;
gameserverip?: string;
gameextrainfo?: string;
loccountrycode?: string;
locstatecode?: string;
loccityid?: number;
};
steamid: string;
username: string;
name: string;
profile: string;
avatar: {
small: string;
medium: string;
large: string;
};
}
export interface SteamRequest extends Request {
logout(): (req: Request) => () => void;
user: SteamUser;
}
export function middleware(opts: MiddlewareOptions): (req: Request, res: Response, next: NextFunction) => void;
export function enforceLogin(redirect: string): (req: Request, res: Response, next: NextFunction) => NextFunction;
export function verify(): (req: Request, res: Response, next: NextFunction) => NextFunction;
export function authenticate(): (req: Request, res: Response, next: NextFunction) => NextFunction;
+35
View File
@@ -0,0 +1,35 @@
// Port of https://github.com/cpancake/steam-login/blob/master/example.js
import * as express from 'express';
import * as steam from 'steam-login';
import * as session from 'express-session';
const app = express();
app.use(session({ resave: false, saveUninitialized: false, secret: 'a secret' }));
app.use(steam.middleware({
realm: 'http://localhost:3000/',
verify: 'http://localhost:3000/verify',
apiKey: process.argv[2]
}
));
app.get('/', (req: steam.SteamRequest, res) => {
res.send(req.user == null ? 'not logged in' : 'hello ' + req.user.username).end();
});
app.get('/authenticate', steam.authenticate(), (req, res) => {
res.redirect('/');
});
app.get('/verify', steam.verify(), (req: steam.SteamRequest, res) => {
res.send(req.user).end();
});
app.get('/logout', steam.enforceLogin('/'), (req: steam.SteamRequest, res) => {
req.logout();
res.redirect('/');
});
app.listen(3000);
console.log('listening');
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": false,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"steam-login-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }