當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript express-jwt.default方法代碼示例

本文整理匯總了TypeScript中express-jwt.default方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript express-jwt.default方法的具體用法?TypeScript express-jwt.default怎麽用?TypeScript express-jwt.default使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在express-jwt的用法示例。


在下文中一共展示了express-jwt.default方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: authenticateUser

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

示例7: 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

示例8: 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

示例9: 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

示例10: 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


注:本文中的express-jwt.default方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。