1.0.1 • Published 4 years ago

@hacdias/indieauth-middleware v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

@hacdias/indieauth-middleware

This is a simple IndieAuth middleware that can be used in conjunction with Express.js or any other framework that uses a similar API.

Install

$ npm i --save @hacdias/indieauth-middleware

Usage

This example uses express.js as the middleware framework but you can use anything as long as you provide an object with the JSON or the form encoded data.

const indieauth = require('@hacdias/indieauth-middleware')
const express = require('express')

const app = express()

app.use(indieauth({
  me: 'https://hacdias.com/',                       // Your domain
  endpoint: 'https://tokens.indieauth.com/token'    // The endpoint used to check the tokens
}))

app.post('/', (req, res) => {
 if (!req.hasScope(['updates'])) {
   // req.hasScope already returns a 401 unauthorized if the user does not
   // have the required scopes.
   return
 }

 // Do your job...
})

Contributing

PRs accepted.

License

MIT © Henrique Dias