Zendesk OAuth2 strategy for Passport.
$ npm install passport-zendesk
var passport = require('passport');
var ZendeskStrategy = require('passport-zendesk').Strategy;
passport.use(new ZendeskStrategy({
subdomain: 'yourZendeskSubdomain',
clientID: 'yourClientIdentifier',
clientSecret: 'yourClientSecret',
callbackURL: 'https://www.example.net/auth/zendesk/callback',
},
function(accessToken, refreshToken, profile, done) {
done(err, user);
}
));
Use passport.authenticate()
, specifying the 'zendesk'
strategy to
authenticate requests.
For example, as route middleware in an Express application:
app.get('/auth/zendesk',
passport.authenticate('zendesk'));
app.get('/auth/zendesk/callback',
passport.authenticate('zendesk', { failureRedirect: '/login' }),
function(req, res) {
// Successful authentication, redirect home.
res.redirect('/');
});
If you've set up a global Zendesk OAuth Client and you wish to authenticate with multiple Zendesk subdomains, passport-zendesk will look for a subdomain parameter in the query string and the post body. Using the configuraiton specified above, a login link for example.zendesk.com would look like this:
<a href="/auth/zendesk?subdomain=example">Login with example.zendesk.com</a>
You may also specify the subdomain explicitly in the authenticate() options:
app.get('/auth/zendesk',
passport.authenticate('zendesk', { subdomain: 'example'}));
For a complete, working sample: login example.