Skip to content

Latest commit

 

History

History
194 lines (125 loc) · 3.61 KB

docs.md

File metadata and controls

194 lines (125 loc) · 3.61 KB

Table of Contents

isAuthenticated

Express middleware for authentication using JWT paradigm

Parameters

  • req
  • res
  • next

Examples

app.get('protectedEndpoint', [isAuthenticated], function(req, res){})

TokenExchange

Abstract implementation of strategy to read/manipulate token in request

Properties

  • read Function (req) - Function that extracts token from request object
  • setTokenReadStrategy Function (strategyInstance) - Set strategy for reading token

Examples

let tokenExchange = new TokenExchange()
// Define your own strategy(a function) to read token, let's call it MyTokenReadStrategy
tokenExchange.setTokenReadStrategy(new MyTokenReadStrategy())
tokenExchange.read(req);
returns token

ReadFromUrlParam

A strategy to read token from request query parameters. Sent via Can be implemted via TokenExchange

Examples

new TokenExchange().setTokenReadStrategy(new ReadFromBody())
// When token was sent /apiEndpoint?access_token=String

ReadFromBody

A strategy to read token from request body Can be implemted via TokenExchange

Examples

new TokenExchange().setTokenReadStrategy(new ReadFromBody())
// When token was sent ia `POST /apiEndpoint -d '{access_token: String}'`

ReadFromCookies

A strategy to read token from request cookies Can be implemted via TokenExchange

Examples

new TokenExchange().setTokenReadStrategy(new ReadFromCookies())

ReadFromHeader

A strategy to read token from request header named authorization Can be implemted via TokenExchange

Parameters

  • req

Examples

new TokenExchange().setTokenReadStrategy(new ReadFromHeader())

ReadFromHeaderWithBearerScheme

A strategy to read token from header with bearer scheme. Can be implemted via TokenExchange

Parameters

  • req any : Express Request object

Examples

new TokenExchange().setTokenReadStrategy(new ReadFromHeaderWithBearerScheme())

setDefaultStrategy

Default strategy when authorization header is available in request : ReadFromHeaderWithBearerScheme Default strategy when cookies have access_token : ReadFromCookie

Parameters

  • req any
  • tokenExchange any