- isAuthenticated
- TokenExchange
- ReadFromUrlParam
- ReadFromBody
- ReadFromCookies
- ReadFromHeader
- ReadFromHeaderWithBearerScheme
- setDefaultStrategy
Express middleware for authentication using JWT paradigm
req
res
next
app.get('protectedEndpoint', [isAuthenticated], function(req, res){})
Abstract implementation of strategy to read/manipulate token in request
read
Function (req) - Function that extracts token from request objectsetTokenReadStrategy
Function (strategyInstance) - Set strategy for reading token
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
- **See: TokenExchange **
A strategy to read token from request query parameters. Sent via Can be implemted via TokenExchange
new TokenExchange().setTokenReadStrategy(new ReadFromBody())
// When token was sent /apiEndpoint?access_token=String
- **See: TokenExchange **
A strategy to read token from request body Can be implemted via TokenExchange
new TokenExchange().setTokenReadStrategy(new ReadFromBody())
// When token was sent ia `POST /apiEndpoint -d '{access_token: String}'`
- **See: TokenExchange **
A strategy to read token from request cookies Can be implemted via TokenExchange
new TokenExchange().setTokenReadStrategy(new ReadFromCookies())
- **See: TokenExchange **
A strategy to read token from request header named authorization
Can be implemted via TokenExchange
req
new TokenExchange().setTokenReadStrategy(new ReadFromHeader())
- **See: TokenExchange **
A strategy to read token from header with bearer scheme. Can be implemted via TokenExchange
req
any : Express Request object
new TokenExchange().setTokenReadStrategy(new ReadFromHeaderWithBearerScheme())
- **See: TokenExchange **
Default strategy when authorization header is available in request : ReadFromHeaderWithBearerScheme
Default strategy when cookies have access_token
: ReadFromCookie
req
anytokenExchange
any