Skip to content

Instantly share code, notes, and snippets.

@dschenkelman
Created February 12, 2021 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dschenkelman/32cec4627078a1582d7fa4bace98e300 to your computer and use it in GitHub Desktop.
Save dschenkelman/32cec4627078a1582d7fa4bace98e300 to your computer and use it in GitHub Desktop.
const express = require('express')
const jwt = require('express-jwt');
const dotenv = require('dotenv');
const constants = require('./constants');
const sandcastle = require('sandcastle');
dotenv.config();
const app = express()
const port = constants.PORT
const authorize = sandcastle.fromExpress(
process.env.SANDCASTLE_URL,
process.env.SANDCASTLE_API_ID,
process.env.SANDCASTLE_API_SECRET);
app.get('/repositories/:id',
jwt({ secret: constants.JWT_SECRET, algorithms: ['HS256'] }),
authorize( req => ({
user: req.user.sub,
relation: 'repo_reader',
object: `github-repo:${req.params.id}`
})),
function(_, res) {
res.sendStatus(200);
}
);
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment