passport-gitlab-token v0.1.0
Passport-Gitlab-Token
Passport strategy for authenticating with GitLab access tokens using the OAuth 2.0 API.
This module lets you authenticate using GitLab in your Node.js applications. By plugging into Passport, GitLab authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.
Installation
npm install passport-gitlab-tokenUsage
Configure Strategy
The GitLab authentication strategy authenticates users using a GitLab
account and OAuth 2.0 tokens. The strategy requires a verify callback, which
accepts these credentials and calls done providing a user, as well as
options specifying a app ID and app secret.
var GitLabTokenStrategy = require('passport-gitlab-token').Strategy;
passport.use(new GitLabTokenStrategy({
clientID: GITLAB_CLIENT_ID,
clientSecret: GITLAB_CLIENT_SECRET
},
function(accessToken, refreshToken, profile, done) {
User.findOrCreate({ gitLabId: profile.id }, function (err, user) {
return done(err, user);
});
}
));Authenticate Requests
Use passport.authenticate('gitlab-token') to authenticate requests.
router.get('/auth/gitlab/token', passport.authenticate('gitlab-token'),
function(req, res) {
res.send(req.user);
});GET request need to have access_token and optionally the refresh_token in either the query string or set as a header. If a POST is being preformed they can also be included in the body of the request.
Credits
License
Copyright (c) 2017 Nazar Mozol
8 years ago