Comments (3)
It depends on your use case.
If all of your Vimeo API requests will be authenticated as a single user (such as if you are building a website that only makes API calls to retrieve https://vimeo.com/dashron's videos) then you can create the library outside of the routes and assign the access token there too.
If your Vimeo API requests will be authenticated by different users depending on who is using your website, you should construct a new Vimeo object within each route, such as below:
// renders a link that redirects the user to vimeo auth
app.get('/', (req, res, next) => {
const vimeo = new Vimeo(VIMEO_CLIENT_ID, VIMEO_CLIENT_SECRET);
const vimeoState = 1; // TODO: change to generate random string
const loginUrl = vimeo.buildAuthorizationEndpoint(VIMEO_REDIRECT_URL, VIMEO_SCOPES, vimeoState);
res.render('index', {loginUrl});
});
// handle response
app.get('/auth', (req, res, next) => {
const vimeo = new Vimeo(VIMEO_CLIENT_ID, VIMEO_CLIENT_SECRET);
const code = req.query.code;
const state = req.query.state;
vimeo.accessToken(code, VIMEO_REDIRECT_URL, (err, token) => {
if (err) { return next(err); }
if (token.access_token) {
// Note: what to do if multiple users connected?
vimeo.access_token = token.access_token;
req.session.vimeo = {token};
}
});
});
from vimeo.js.
Thanks, just as I thought.
Also note for anyone reading it: Good idea to wrap the Vimeo
instance creation in an factory-function. So you won't need to reference the client_id
, ... all the time.
from vimeo.js.
Totally agree about the factory function. In my personal work I tend to have something like...
/src/lib/Vimeo.js
const config = require('config');
const Vimeo = require('vimeo');
module.exports = function getVimeoLib () {
return new Vimeo(config.get('vimeo.client_id'), config.get('vimeo.client_secret'));
};
Which my code can use like this:
var lib = require('./src/lib/vimeo.js').getVimeoLib();
// use the lib
from vimeo.js.
Related Issues (20)
- Multiple iFrame end listener event only works for the first video HOT 1
- error: connect ECONNREFUSED 127.0.0.1:80 HOT 2
- Vimeo uploads stopped working
- Upload videos from an SPA (Angular 12) - Which is the best approach? HOT 3
- Can't use the repo to upload any video. HOT 3
- require is not defined HOT 1
- adding thumbnail to video HOT 9
- How to use Vimeo in ViteJS? HOT 1
- Upload fails when video smaller than 0.5s HOT 1
- Compilation Error 'Module not found: Error:' HOT 3
- Error in documention : Pull approach
- player not fullscreen capable on Android HOT 1
- Vimeo Client ignores any upload paramaters HOT 2
- How to add markers to vimeo video HOT 4
- vimeo sdk 2.x support HOT 1
- Document passing `body` via `client.request()` (using `query` and `headers['Content-Type']`) HOT 4
- Node Express - Vimeo upload file size problem
- Sorry, but where is the typescript support? HOT 3
- Function `access_token` returns bad request
- Encountering TLS CERT_HAS_EXPIRED Error Despite Previous Functionality HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vimeo.js.