diff --git a/types/steam-login/index.d.ts b/types/steam-login/index.d.ts new file mode 100644 index 0000000000..13fc21c691 --- /dev/null +++ b/types/steam-login/index.d.ts @@ -0,0 +1,61 @@ +// Type definitions for steam-login 0.1 +// Project: http://github.com/cpancake/steam-login +// Definitions by: Nick Winans +// 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; diff --git a/types/steam-login/steam-login-tests.ts b/types/steam-login/steam-login-tests.ts new file mode 100644 index 0000000000..e741a0f5de --- /dev/null +++ b/types/steam-login/steam-login-tests.ts @@ -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'); diff --git a/types/steam-login/tsconfig.json b/types/steam-login/tsconfig.json new file mode 100644 index 0000000000..a1d49993f6 --- /dev/null +++ b/types/steam-login/tsconfig.json @@ -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" + ] +} diff --git a/types/steam-login/tslint.json b/types/steam-login/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/steam-login/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }