How to use accessTokenAuth method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

server.js

Source:server.js Github

copy

Full Screen

1if (process.env.NEW_RELIC_LICENSE_KEY && process.env.NEW_RELIC_APP_NAME) {2 require('newrelic');3}4var express = require('express')5 , app = express()6 , server = require('http').createServer(app)7 , BearerStrategy = require('passport-http-bearer').Strategy8 , config = require('./config')9 , controllers = require('./controllers')10 , ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn(config.user_login_path)11 , exphbs = require('express-handlebars')12 , hbs = exphbs.create({ defaultLayout: 'main' })13 , LocalStrategy = require('passport-local').Strategy14 , log = require('./log')15 , middleware = require('./middleware')16 , models = require('./models')17 , mongoose = require('mongoose')18 , passport = require('passport')19 , path = require('path')20 , PublicKeyStrategy = require('passport-publickey').Strategy21 , services = require('./services')22 , utils = require('./utils');23log.info("connecting to mongodb instance: " + config.mongodb_connection_string);24mongoose.connect(config.mongodb_connection_string);25app.use(express.logger(config.request_log_format));26app.use(express.compress());27app.use(express.bodyParser());28app.use(express.cookieParser());29app.use(express.cookieSession({30 secret: config.user_session_secret,31 cookie: {32 expires: new Date(Date.now() + config.user_session_timeout_seconds * 1000),33 maxAge: new Date(Date.now() + config.user_session_timeout_seconds * 1000),34 }35}));36app.use(passport.initialize());37app.use(passport.session());38passport.use(new BearerStrategy({}, services.accessTokens.verify));39passport.use(new PublicKeyStrategy({}, services.principals.verifySignature));40app.use(middleware.crossOrigin);41app.enable('trust proxy');42app.disable('x-powered-by');43app.engine('handlebars', hbs.engine);44app.set('view engine', 'handlebars');45// only open endpoints when we have a connection to MongoDB.46mongoose.connection.once('open', function () {47 log.info("service connected to mongodb.");48 services.initialize(function(err) {49 if (err) return log.error("service failed to initialize: " + err);50 if (!services.principals.servicePrincipal) return log.error("Service principal not available after initialize.");51 server.listen(config.internal_port);52 services.subscriptions.attach(server);53 log.info("service has initialized itself, exposing api at: " + config.api_endpoint);54 // REST API ENDPOINTS55 // headwaiter endpoint56 app.get(config.headwaiter_path, controllers.headwaiter.index);57 app.get(config.api_keys_path, middleware.accessTokenAuth, controllers.apiKeys.index);58 app.post(config.api_keys_path, middleware.accessTokenAuth, controllers.apiKeys.create);59 // blob endpoints60 if (config.blob_provider) {61 app.get(config.blobs_path + '/:id', middleware.accessTokenAuth, controllers.blobs.show);62 app.post(config.blobs_path, middleware.accessTokenAuth, controllers.blobs.create);63 } else {64 log.warn("not exposing blob endpoints because no blob provider configured (see config.js).");65 }66 // ops endpoints67 app.get(config.ops_path + '/health', controllers.ops.health);68 app.get(config.ops_path + '/stats', controllers.ops.stats);69 // permissions endpoints70 app.get(config.permissions_path, middleware.accessTokenAuth, controllers.permissions.index);71 app.post(config.permissions_path, middleware.accessTokenAuth, controllers.permissions.create);72 app.delete(config.permissions_path + '/:id', middleware.accessTokenAuth, controllers.permissions.remove);73 // principal endpoints74 app.post(config.principals_path + '/auth', controllers.principals.legacyAuthentication);75 app.post(config.principals_path + '/publickey/auth', middleware.publicKeyAuth, controllers.principals.authenticate);76 app.post(config.principals_path + '/secret/auth', middleware.secretAuth, controllers.principals.authenticate);77 app.get(config.principals_path + '/:id', middleware.accessTokenAuth, controllers.principals.show);78 app.get(config.principals_path, middleware.accessTokenAuth, controllers.principals.index);79 // TODO: CLI needs auth user and create user endpoints for now.80 app.post(config.principals_path + '/user/auth', controllers.principals.authenticateUser);81 app.post(config.principals_path, controllers.principals.create);82 app.post(config.principals_path + '/accesstoken', middleware.accessTokenAuth, controllers.principals.accessTokenFor);83 app.post(config.principals_path + '/impersonate', middleware.accessTokenAuth, controllers.principals.impersonate);84 app.put(config.principals_path + '/:id', middleware.accessTokenAuth, controllers.principals.update);85 app.delete(config.principals_path + '/:id', middleware.accessTokenAuth, controllers.principals.remove);86 // message endpoints87 app.get(config.messages_path + '/:id', middleware.accessTokenAuth, controllers.messages.show);88 app.get(config.messages_path, middleware.accessTokenAuth, controllers.messages.index);89 app.post(config.messages_path, middleware.accessTokenAuth, controllers.messages.create);90 app.delete(config.messages_path, middleware.accessTokenAuth, controllers.messages.remove);91 // USER AND OAUTH2 ENDPOINTS92 // create user93 app.get(config.user_create_path, controllers.users.createForm);94 app.post(config.user_create_path, controllers.users.create);95 // login user96 app.get(config.user_login_path, controllers.users.loginForm);97 app.post(config.user_login_path, controllers.users.login);98 // change password99 app.get(config.user_change_password_path, ensureLoggedIn, controllers.users.changePasswordForm);100 app.post(config.user_change_password_path, ensureLoggedIn, controllers.users.changePassword);101 // delete account102 app.get(config.user_delete_account_path, ensureLoggedIn, controllers.users.deleteAccountForm);103 app.post(config.user_delete_account_path, ensureLoggedIn, controllers.users.deleteAccount);104 // reset password105 app.get(config.user_reset_password_path, controllers.users.resetPasswordForm);106 app.post(config.user_reset_password_path, controllers.users.resetPassword);107 // logout108 app.get(config.user_logout_path, ensureLoggedIn, controllers.users.logout);109 // privacy policy and terms of service110 app.get(config.users_path + "/privacy", controllers.users.privacy);111 app.get(config.users_path + "/terms", controllers.users.terms);112 // user serialization and deserialization113 passport.serializeUser(function(user, done) {114 done(null, user.id);115 });116 passport.deserializeUser(function(id, done) {117 services.principals.findByIdCached(services.principals.servicePrincipal, id, done);118 });119 // oauth2 endpoints120 app.get(config.users_path + '/impersonate', ensureLoggedIn, controllers.users.impersonate);121 app.get(config.users_path + '/authorize', ensureLoggedIn, controllers.users.authorize);122 app.post(config.users_path + '/decision', ensureLoggedIn, controllers.users.decision);123 // client libraries124 app.get('/client/nitrogen.js', function(req, res) {125 res.contentType('application/javascript');126 res.send(services.messages.clients['nitrogen.js']);127 });128 app.get('/client/nitrogen-min.js', function(req, res) {129 res.contentType('application/javascript');130 res.send(services.messages.clients['nitrogen-min.js']);131 });132 // static files (static/ is mapped to the root API url for any path not already covered above)133 app.use(express.static(path.join(__dirname, '/static')));134 log.info("service has initialized API endpoints");135 mongoose.connection.on('error', log.error);136 });...

Full Screen

Full Screen

payroll.js

Source:payroll.js Github

copy

Full Screen

...8 router.get(`${ENDPOINT}/test`, asyncMiddleware(controller.payrollController.test)),9 router.post(10 `${ENDPOINT}/create`,11 PayrollValidator,12 middleware.accessTokenAuth("payroll.write"),13 asyncMiddleware(controller.payrollController.create)14 ),15 router.get(16 `${ENDPOINT}/getall`,17 middleware.accessTokenAuth("payroll.read"),18 asyncMiddleware(controller.payrollController.getAll)19 ),20 router.get(21 `${ENDPOINT}/getone`,22 middleware.accessTokenAuth("payroll.read"),23 asyncMiddleware(controller.payrollController.getOne)24 ),25 router.put(26 `${ENDPOINT}/update`,27 middleware.accessTokenAuth("payroll.edit"),28 PayrollValidator,29 asyncMiddleware(controller.payrollController.update)30 ),31 router.get(32 `${ENDPOINT}/updateAndGetNextValue`,33 middleware.accessTokenAuth("payroll.read"),34 // loginRequired, //@todo get another authenticator for in-house product communication35 asyncMiddleware(controller.payrollController.updateAndgetSequenceNextValue)36 );...

Full Screen

Full Screen

security.js

Source:security.js Github

copy

Full Screen

1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3exports.accessTokenAuth = void 0;4const accessTokenAuth = (req, res, next) => {5 const accessToken = req.header('X-Access-Token');6 if (!accessToken) {7 return res.status(401).json({8 code: 50001,9 messaege: 'Invalid Access Token'10 });11 }12 next();13};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2client.getDevices().then(function(devices) {3 console.log(devices);4});5var stf = require('devicefarmer-stf-client');6client.getDevices().then(function(devices) {7 console.log(devices);8});9var stf = require('devicefarmer-stf-client');10client.getDevices().then(function(devices) {11 console.log(devices);12});13var stf = require('devicefarmer-stf-client');14client.getDevices().then(function(devices) {15 console.log(devices);16});17var stf = require('devicefarmer-stf-client');18client.getDevices().then(function(devices) {19 console.log(devices);20});21var stf = require('devicefarmer-stf-client');22client.getDevices().then(function(devices) {23 console.log(devices);24});25var stf = require('devicefarmer-stf-client');26client.getDevices().then(function(devices) {27 console.log(devices);28});29var stf = require('devicefarmer-stf-client');30client.getDevices().then(function(devices) {31 console.log(devices);32});

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var device = client.getDevice('deviceID');3device.accessTokenAuth('accessToken');4var stf = require('stf');5var device = client.getDevice('deviceID');6device.accessTokenAuth('accessToken');7var stf = require('devicefarmer-stf-client');8var device = client.getDevice('deviceID');9device.accessTokenAuth('accessToken');10var stf = require('devicefarmer-stf-client');11var device = client.getDevice('deviceID');12device.accessTokenAuth('accessToken');13var stf = require('devicefarmer-stf-client');14var device = client.getDevice('deviceID');15device.accessTokenAuth('accessToken');16var devices = client.getDevices();17devices.then(function (devices) {18 console.log(devices);19});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run devicefarmer-stf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful