simple:authenticate-user-by-token

v1.2.1Published 2 years ago

Compatibility

Compatible with Meteor 2.4

This repository provides versions for the package simple:authenticate-user-by-token that are compatible with latest Meteor. This is necessary because the author is not maintaining package anymore.

Changes

  • v1.2.1
    • Update simple:json-routes to 2.3.0
  • v1.2.0
    • api.versionsFrom on Package.onUse was changed from 1.0 to 2.4.

simple:authenticate-user-by-token

SimpleRest middleware for validating a Meteor.user's login token

Middleware Name

This middleware can be accessed as:

JsonRoutes.Middleware.authenticateMeteorUserByToken

Request Properties Required

  • request.authToken
    • String
    • A valid login token for a Meteor.user account (requires accounts-base)

Request Properties Modified

  • request.userId
    • String
    • If the request.authToken is found in a user account, sets this to the ID of the authenticated user. Otherwise, null.

Usage

Simply add this layer of middleware after any token parsing middleware, and voila!

For example:

1JsonRoutes.Middleware.use('/auth', JsonRoutes.Middleware.parseBearerToken);
2JsonRoutes.Middleware.use('/auth', JsonRoutes.Middleware.authenticateMeteorUserByToken);
3
4JsonRoutes.add('GET', 'auth/test', function (request, response) {
5  // The authenticated user's ID will be set by this middleware
6  var userId = request.userId;
7});