本文整理汇总了TypeScript中express-jwt类的典型用法代码示例。如果您正苦于以下问题:TypeScript express-jwt类的具体用法?TypeScript express-jwt怎么用?TypeScript express-jwt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了express-jwt类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: expressJWT
import { Router, Request, Response, RequestHandler } from 'express';
import { User, UserDataStore } from '../services/user-datastore';
import * as expressJWT from "express-jwt";
import * as jwt from "jsonwebtoken";
const TOKEN_SECRET = 'CryptoGraphix';
export var tokenValidator = expressJWT( { secret: TOKEN_SECRET } );
/**
* Express middleware to authenticate a user
* For now, just retrieves a 'user' cookie, that is the logged-in username
* If OK, the 'req' object will gain a user property on exit
* If NOK, fail with a 401 (unauthorized) error code
*/
export function authenticateUser( req, res, next ) {
// We need a user (extracted and validated by express-jwt)
if ( req.user ) {
console.log( req.user );
next();
}
else
res.sendStatus( 401 );
}
/**
* Create and export sub-router for '/api/auth'
*/
开发者ID:cryptographix,项目名称:labs-workshop-secure-web-applications,代码行数:31,代码来源:auth.ts
示例2: jwt
import * as express from 'express';
import * as jwt from 'express-jwt';
import * as controller from './controller';
const router = express.Router();
const auth = jwt({
userProperty: 'payload',
secret: process.env.JWT_SECRET
});
//BASE ROUTE: '/api/v1/items'
//GET: '/api/v1/items/user/:id'
router.get('/user/:id', controller.getAll);
//GET: '/api/v1/items/:id'
router.get('/:id', controller.getOne);
//POST: '/api/v1/items'
router.post('/', auth, controller.create);
//PUT: '/api/v1/items/:id'
router.put('/:id', auth, controller.update);
//DELETE: '/api/v1/items/:id'
router.delete('/:id', auth, controller.remove);
export = router;
开发者ID:Jeremy-Doucet,项目名称:March-7-Group-Project,代码行数:28,代码来源:routes.ts
示例3: express
import eventbriteSync from "./middleware/eventbrite-sync";
import * as config from "./config";
import reviver from "./middleware/reviver";
import addDataContext from "./middleware/add-data-context";
import * as eventApi from "./middleware/events-api";
import * as participantsApi from "./middleware/participants-api";
import * as sessions from "./middleware/sessionpicker-api";
import setupDb from "./middleware/db-setup-api";
import * as appinsights from "applicationinsights";
import * as jwt from "express-jwt";
import apiKeyAuth from "./middleware/key-auth";
appinsights.setup(config.APP_INSIGHTS_KEY).start();
var app = express();
const jwtCheck = jwt({ secret: config.AUTH0_SECRET, audience: config.AUTH0_CLIENT });
const jwtOptionalCheck = jwt({ secret: config.AUTH0_SECRET, audience: config.AUTH0_CLIENT, credentialsRequired: false });
const jwtCheckSessionpicker = jwt({ secret: config.AUTH0_SECRET_SESSIONPICKER, audience: config.AUTH0_CLIENT_SESSIONPICKER });
// Create express server
app.use(cors());
var bodyParserOptions = { reviver: reviver };
app.use(bodyParser.json(bodyParserOptions));
// Endpoint for initializing the DB. Will return an error if DB already initialized
app.get("/admin/db-setup", jwtCheck, setupDb);
// Endpoint for triggering Eventbrite sync
app.post("/admin/eventbrite-sync", jwtCheck, ensureAdmin, eventbriteSync);
// Events API
开发者ID:coderdojo-linz,项目名称:participants-management-service,代码行数:31,代码来源:server.ts
示例4: express
import * as express from 'express';
import * as util from 'gulp-util';
import * as chalk from 'chalk';
import * as jwt from 'express-jwt';
import * as _ from 'lodash';
import {User} from './user';
import {UserContainer} from './user.container';
const EXPRESS_APP = express();
EXPRESS_APP.use(express.static(__dirname + '/../app'));
EXPRESS_APP.use(express.static(__dirname + '/../../../'));
const userContainer=new UserContainer(1000000);
const JWT_CHECK=jwt({
secret: new Buffer("VqPEjyiGncpqLZoPFgZNUIQsEcVRbZ4vcjN85uQF5cTaAHCIauUacPTdQ_f0OzZ1", 'base64'),
audience: 'bUfoWb8hk8OsP9VUV2gpr7WlFE5LOWb9'
});
const QUOTES:string[]=[
"Hey I'm this API server!",
"API Server says hello to you visitor!",
"You are welcome!"
]
EXPRESS_APP.use('/', JWT_CHECK);
EXPRESS_APP.get('/', (req: express.Request, res: express.Response) => {
res.json('Welcome to the builder APP REST API!');
});
EXPRESS_APP.get('/users', (req: express.Request, res: express.Response)=>{
res.json({
开发者ID:Jaroost,项目名称:builder_app,代码行数:31,代码来源:server.ts
示例5: callback
server.setConfig((app) => {
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(morgan('combined'));
app.use(cors({
origin: (origin, callback) => {
try {
let ok: boolean = config.originsWhitelist.indexOf(origin) !== -1
callback(null, ok);
} catch (e) {
callback(e, null);
}
}
}));
app.use(jwt({ secret: config.appSecret })
.unless({
path: ['/api/account/login', '/setup', '/',
{
url: '/api/donors',
methods: ['GET', 'POST']
}]
}));
let feed: DonorsFeed = kernel.get<DonorsFeed>(TYPES.DonorsFeed);
feed.start(httpServer);
});
开发者ID:kibiluzbad,项目名称:kamrusepa,代码行数:28,代码来源:server.ts
示例6: expressJwt
const protect = () => {
return expressJwt({
secret: config.security.tokenSecret,
getToken: (req: Request) => {
return req.cookies.token;
},
}).unless({path: [ '/api/login', '/api/register', '/api/logout' ]});
};
开发者ID:PhilipDavis,项目名称:react-redux,代码行数:8,代码来源:index.ts
示例7: return
return (req, res, next) => {
jwt({
secret: expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: `https://${EnvConfig.AUTH0_DOMAIN}/.well-known/jwks.json`
}),
aud: EnvConfig.AUTH0_AUDIENCE,
iss: `https://${EnvConfig.AUTH0_DOMAIN}/`,
algorithm: 'RS256'
})(req, res, this.next.bind(this, next));
};
开发者ID:oliutiano,项目名称:hyperledger-typescript-boilerplate,代码行数:13,代码来源:jwtauthentication.middleware.ts
示例8: callback
server.setConfig((app) => {
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(morgan('combined'));
app.use(cors({
origin: (origin, callback) => {
try {
let ok: boolean = config.originsWhitelist.indexOf(origin) !== -1
callback(null, ok);
} catch (e) {
callback(e, null);
}
}
}));
app.use(jwt({ secret: config.appSecret})
.unless({path: ['/api/account/login', '/setup', '/']}));
});
开发者ID:marinet-web,项目名称:marinet-api,代码行数:20,代码来源:server.ts
示例9: cb
setupSwagger() {
// resolve the spec
const spath = path.resolve('swagger.yml');
const file = fs.readFileSync(spath, 'utf8');
const spec = yaml.safeLoad(file);
// init jwt middleware
const jwtSecret = config.get('auth.jwt_secret').toString();
let jwt = expressJwt({
secret: new Buffer(jwtSecret, 'base64')
});
// setup middleware swagger middleware in express
swaggerTools.initializeMiddleware(spec, (middleware) => {
this.app.use(middleware.swaggerMetadata());
this.app.use(middleware.swaggerValidator({
validateResponse: true
}));
this.app.use(middleware.swaggerSecurity({
jwt_token: (req, authOrSecDef, scopes, cb) => {
jwt(req, req.res, (err) => {
if (req.userName === undefined) {
return cb(new Error('Access Denied!'));
} else {
logger.info(`${req.userName} authorized`, req.userName);
return cb(null);
}
});
}
}));
this.app.use(middleware.swaggerUi());
});
}
开发者ID:efueger,项目名称:node-microservice-demo,代码行数:36,代码来源:Express.ts
示例10: express
*/
const app = express();
const hostname = process.env.HOSTNAME || 'localhost';
const port = parseInt(process.env.PORT, 10) || 3000;
const isDev = 'development' === app.get('env');
const publicDir = process.argv[2] || path.join(__dirname, '..', '..', 'client');
app
.use(morgan('dev'))
.use(bodyParser.json())
.get('/index.dev.html', (req, res) =>
res.redirect(301, '/')
)
.get('/index.prod.html', (req, res) =>
res.redirect(301, '/')
)
.use(express.static(publicDir))
.use('/auth', authRoutes)
.get('/secret', jwtMiddleware({
secret: config.auth.TOKEN_SECRET
}), (req, res) => res.send('4 8 15 16 23 42'))
.get("*", (req, res) =>
res.sendFile(path.join(publicDir, isDev ? "index.dev.html" : "index.prod.html"))
)
.listen(port, hostname, () =>
console.log(`Server listening at http://${hostname}:${port} ${app.get('env')}`)
);
开发者ID:royipressburger,项目名称:ng2-ui-auth-example,代码行数:29,代码来源:server.ts
注:本文中的express-jwt类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论