Created
February 12, 2021 13:24
-
-
Save dschenkelman/32cec4627078a1582d7fa4bace98e300 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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