本文整理汇总了TypeScript中express-jwt.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: function
export default function(app: express.Application) {
var _tokenHelper = tokenHelper(redisconfig.client);
var _authCtrl = auth(User, _tokenHelper);
var _apiCtrl = api(User, sendResetMail);
/**
* User profile api
*/
app.route('/api/profile').post(jwt({
secret: nconf.get("jwtAuth").secret,
isRevoked: _tokenHelper.isRevoked
}), _apiCtrl.postProfile);
app.route('/api/profile').put(jwt({
secret: nconf.get("jwtAuth").secret,
isRevoked: _tokenHelper.isRevoked
}), _apiCtrl.updateProfile);
app.route("/api/account").post(jwt({
secret: nconf.get("jwtAuth").secret,
isRevoked: _tokenHelper.isRevoked
}), _apiCtrl.postAccount);
app.route('/api/updateaccount').post(jwt({
secret: nconf.get("jwtAuth").secret,
isRevoked: _tokenHelper.isRevoked
}), _apiCtrl.updateAccount);
app.route('/api/forgot').post(_apiCtrl.forgot);
app.route('/api/resetpassword/').post(_apiCtrl.setNewPassword);
app.route('/api/reset/:token').get(_apiCtrl.validateResetToken);
/**
* Local authentication api
*/
app.route('/auth/signup').post(_authCtrl.signup);
app.route('/auth/signin').post(_authCtrl.signin);
app.route('/auth/signout').post(jwt({
secret: nconf.get("jwtAuth").secret,
isRevoked: _tokenHelper.isRevoked
}), _authCtrl.signout);
app.route('/auth/me').post(jwt({
secret: nconf.get("jwtAuth").secret,
isRevoked: _tokenHelper.isRevoked
}), _authCtrl.me);
/**
* Github authentication routes
*/
app.route('/external/github').get(passport.authenticate('github', {
scope: ['user:email']
}));
app.route('/external/github/callback').get(_authCtrl.oauthCallback('github'));
};
开发者ID:cm0s,项目名称:mea2n,代码行数:52,代码来源:user.routes.ts
示例2: startPublications
export function startPublications() {
const mode = process.env.NODE_ENV || "DEVELOPMENT";
const app = express();
if (mode.toUpperCase() === "DEVELOPMENT") {
const compiler = webpack(webpackConfig as webpack.Configuration);
app.use(
webpackDevMiddleware(compiler, {
publicPath: webpackConfig.output.publicPath,
})
);
app.use(webpackHotMiddleware(compiler));
app.use("/playground", graphqlPlayground({ endpoint: "/graphql" }));
} else {
const publicPath = path.resolve(__dirname, "../public");
app.use(express.static(publicPath));
app.get("*", (req, res) =>
res.sendFile(path.resolve(publicPath, "index.html"))
);
}
app.use(jwt(jwtConfig));
app.use(
"/graphql",
graphqlHttp(request => ({
schema,
context: { user: request.user },
}))
);
app.use(onAuthError);
app.get("/documents/:id/pdf", documentPdfHandler);
app.listen(PORT, () => {
console.log(`Publications started on port ${PORT}.`);
});
}
开发者ID:carlospaelinck,项目名称:publications-js,代码行数:35,代码来源:index.ts
示例3: AuthRoutes
constructor(public app: Application, public router: Router) {
new AuthRoutes(app);
new CategoryRoutes(router);
new GameRoutes(router);
const unprotected = ['/api/alive', '/api/games-create', '/api/games-join'];
app.use('/api/', expressJwt({ secret }).unless({ path: unprotected }), router);
app.get('/report/', (req, res) => {
r.table('players').count().then(count => {
res.json(count);
})
});
}
开发者ID:radotzki,项目名称:bullshit-server,代码行数:14,代码来源:routes.ts
示例4: ArgumentError
export const auth0ify = (options: Auth0ifyOptions) => {
if (!options || !(options instanceof Object)) {
throw new ArgumentError('The options must be an object.')
}
if (!options.clientId || options.clientId.length === 0) {
throw new ArgumentError(
'The Auth0 Client or API ID has to be provided.'
)
}
if (!options.clientSecret || options.clientSecret.length === 0) {
throw new ArgumentError(
'The Auth0 Client or API Secret has to be provided.'
)
}
if (!options.domain || options.domain.length === 0) {
throw new ArgumentError('The Auth0 Domain has to be provided.')
}
const middleware = jwt({
secret: options.clientSecret,
audience: options.clientId,
issuer: options.domain,
algorithms: options.algorithms
})
return (
requiredScopes: string[],
next: (c: HttpContext, r: Auth0FunctionRequest) => any
) => {
return (context: HttpContext, req: Auth0FunctionRequest) => {
middleware(req, null, (err: any) => {
if (err) {
const res = {
status: err.status || 500,
body: {
message: err.message
}
}
return context.done(null, res)
}
const allowedScopes = req.user.scope.split(' ')
const sufficent = requiredScopes.every(
scope => allowedScopes.indexOf(scope) !== -1
)
if (!sufficent) {
const res = {
status: 403,
body: {
message: 'Forbidden'
}
}
return context.done(null, res)
}
return next(context, req)
})
}
}
}
开发者ID:OpenDirective,项目名称:brian,代码行数:64,代码来源:auth0ify.ts
示例5: require
let jwt = require("express-jwt");
export let auth = jwt({
secret: process.env.APP_SECRET
});
开发者ID:galyna,项目名称:PalamarGroup,代码行数:5,代码来源:auth.ts
示例6: isAuthenticated
/// <reference path="../../typings/main.d.ts" />
"use strict";
var mongoose = require('mongoose');
var passport = require('passport');
var jwt = require('jsonwebtoken');
var expressJwt = require('express-jwt');
var compose = require('composable-middleware');
var User = require('../../api/user/model/user-model');
var secretSession = 'ppt-secret';
var validateJwt = expressJwt({secret: secretSession});
export class AuthService {
/**
* Attaches the user object to the request if authenticated
* Otherwise returns 403
*/
static isAuthenticated() {
return compose()
// Validate jwt
.use(function (req, res, next) {
// allow access_token to be passed through query parameter as well
if (req.query && req.query.hasOwnProperty('access_token')) {
req.headers.authorization = 'Bearer ' + req.query.access_token;
}
validateJwt(req, res, next);
})
// Attach user to request
.use(function (req, res, next) {
开发者ID:suvetig,项目名称:ppt,代码行数:31,代码来源:auth-service.ts
示例7: isAuthenticated
import User from '../api/user/user.model';
import config from '../../../config';
import * as jwt from 'jsonwebtoken';
let expressJwt = require('express-jwt');
let compose = require('composable-middleware');
let validateJwt = expressJwt({
secret: config.sessionSecret
});
/**
* Attaches the user object to the request if authenticated
* Otherwise returns 403
*/
export function isAuthenticated() {
return compose()
// Validate jwt
.use((req, res, next) => {
// allow access_token to be passed through query parameter as well
if (req.query && req.query.hasOwnProperty('access_token')) {
req.headers.authorization = 'Bearer ' + req.query.access_token;
}
return validateJwt(req, res, next);
})
// Attach user to request
.use((req, res, next) => {
return User.findById(req.user.id)
.then(user => {
开发者ID:projectSHAI,项目名称:expressgular2,代码行数:31,代码来源:auth.service.ts
示例8: require
var bodyParser = require('body-parser');
var expressJWT = require('express-jwt');
import st = require('./student');
import bd = require('./buddy');
import da = require('./dal');
import rs = require('./resource');
import fl = require('./file');
import jwt = require('./jwtManage');
// Add Error Handler
var app = express();
app.use(express.static("../ShareIt-Client"));
app.use(expressJWT({ secret: jwt.JwtManager.publicKey }).unless({
path: ['/', '/api/Students', '/api/Files']
}));
var server = http.Server(app);
var io = require('socket.io')(server);
var port = process.env.port || 8080;
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
app.get('/', (req, res) => {
fs.readFile('index.html',
(err, data) => {
开发者ID:prncher,项目名称:ShareIt-Nodejs,代码行数:31,代码来源:server.ts
示例9: initDb
import app, {serveStatic, configService} from './';
import {initDb} from './db/init-test-data';
import expressJwt from 'express-jwt';
import {articleService} from './services/article';
import {signinService} from './services/signin';
import {swaggerService} from './swagger/index';
serveStatic('', app);
app.use(expressJwt({secret: 'secret', credentialsRequired: false}));
// When testing, we recreate the db for each request.
if (process.env.DB_ENV === 'test') {
app.use(async (req, res, next) => {
await initDb();
next();
});
}
articleService('', app);
configService('', app);
signinService('', app);
swaggerService('', app);
app.listen(1337, () => console.log('Launching app on port 1337.'));
开发者ID:get-focus,项目名称:focus-help-center,代码行数:25,代码来源:default.ts
示例10:
app.use(express.static(process.env.NODE_ENV === 'production' ? PATH_PUBLIC_PROD : PATH_PUBLIC_DEV));
app.use(express.static(process.env.NODE_ENV === 'production' ? PATH_IMAGES_PROD : PATH_IMAGES_DEV));
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Authorization, Origin, X-Requested-With, Content-Type, Accept');
next();
});
// use JWT auth to secure the api, the token can be passed in the authorization header or query string
app.use(expressJwt({
secret: config.token.secret,
getToken(req) {
if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer')
return req.headers.authorization.split(' ')[1];
return null;
}
}).unless((req) => {
return (
(/\.(gif|jpg|jpeg|tiff|png|ico)$/i).test(req.originalUrl) ||
req.originalUrl === '/' ||
req.originalUrl.startsWith('/ws/') ||
req.originalUrl.startsWith('/assets/') ||
(req.originalUrl === '/api/v1/authenticate' && (['POST', 'PUT', 'OPTIONS'].includes(req.method) && !req.headers.authorization)) ||
req.originalUrl === '/api/v1/authenticate/request-password-reset' ||
(req.originalUrl === '/api/v1/user' && (req.method === 'POST' || req.method === 'OPTIONS'))
);
}));
开发者ID:Chegeek,项目名称:TradeJS,代码行数:29,代码来源:app.ts
注:本文中的express-jwt.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论