Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

bearer-token

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bearer-token

Returns rfc6750 OAuth Bearer Token from an http request object

latest
Source
npmnpm
Version
2.0.2
Version published
Weekly downloads
32
6.67%
Maintainers
1
Weekly downloads
 
Created
Source

bearer-token

npm travis

Callback with a rfc6750 OAuth 2.0 Bearer Token from an http request object, ready for verification.

Install

npm install bearer-token

Example

var bearerToken = require('bearer-token')
var http = require('http')

server = http.createServer()
server.listen(8000, function () {
  console.log('server started on 8000')
})

server.on('request', function(req ,res) {
  bearerToken(req, function(err, token) {
    // Now you have to verify the token
  })
})

Pass in a standard http reuest object to extract a single bearer token from the request in the callback, if it exists. If no bearer token is found, token will be undefined. The first bearer token that is found is returned. Authentication headers take precidence over tokens found in the body.

Arguments

var bearerToken = require('bearer-token')

bearerToken is a single asyncronous function.

bearerToken(req, callback)

  • req Accepts a standard http request object. The request header and body are parsed in search of a bearer token. Tokens found in the request header take precidence over tokens in the body.
  • callback(error, token) Function is called with any errors and a token if found. A missing token is not grounds for an error (only parsing or unexpected errors).
    • error Error object if anything bad happened.
    • token String if a token is found. You still need to verify it.

Contributing

Contributions welcome! Please read the contributing guidelines first.

Contributors

bcomnesGitHub/bcomnes
wpacksGitHub/wpacks

License

ISC

Keywords

authentication

FAQs

Package last updated on 21 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts