本文整理匯總了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'));
};
示例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}.`);
});
}
示例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);
})
});
}
示例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)
})
}
}
}
示例5: require
let jwt = require("express-jwt");
export let auth = jwt({
secret: process.env.APP_SECRET
});
示例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) {
示例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 => {
示例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) => {
示例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.'));
示例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'))
);
}));