mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 23:07:06 +00:00
steam-login: add types
This commit is contained in:
Vendored
+61
@@ -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;
|
||||
@@ -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');
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user