Created
December 4, 2020 12:58
-
-
Save akkikumar72/31f2563c2b88c0897f5234cae7a8a20d to your computer and use it in GitHub Desktop.
Atlassian 3LO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable import/no-extraneous-dependencies */ | |
const express = require('express'); | |
const passport = require('passport'); | |
const AtlassianStrategy = require('passport-atlassian-oauth2'); | |
// Configure Atlassian OOuth2 strategy for use by Passport. | |
passport.use(new AtlassianStrategy({ | |
clientID: 'keeL5Ne1bv4bwhskjKGRdYZ1kkOgQufz', | |
clientSecret: 'k-UOpaxpek7kFDIYOg9Z9kbXDlmjyJzSdUohOxLsSy0lCOQyAZxHxgKKd3LtS2gI', | |
callbackURL: 'http://localhost:8080/auth/atlassian/callback', | |
scope: 'offline_access read:me', | |
}, (accessToken, refreshToken, profile, cb) => { | |
// Profile should be stored to the database in real applications | |
console.log(JSON.stringify(profile, null, 2)); | |
cb(null, profile); | |
})); | |
// Dummy serialization/desiarialization | |
passport.serializeUser((user, cb) => cb(null, user)); | |
passport.deserializeUser((obj, cb) => cb(null, obj)); | |
const app = express(); | |
app.use(passport.initialize()); | |
app.use(passport.session()); | |
app.get('/auth/atlassian', passport.authenticate('atlassian')); | |
app.get('/auth/atlassian/callback', passport.authenticate('atlassian', { failureRedirect: '/error' }), (req, res) => { | |
// Successfull authorization, redirect user to profile page | |
res.redirect('/profile-page'); | |
}); | |
app.get('/profile-page', (req, res) => { | |
res.send('It works!'); | |
}); | |
app.get('/error', (req, res) => { | |
res.send('Authorization error :('); | |
}); | |
app.listen(8080, () => console.log('server started on port 8080')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment