JsonRoute with Basic Authentication?

Hi there,
Trying to figure out the syntax for Basic Authentication with JsonRoutes. I’ve figured out how to pass around tokens for OAuth, but am still a bit fuzzy on Basic Auth.

Let’s say we’re talking about the following function:

HTTP.call('post', 'http://foo.meteorapp.com/api/xyz', {
  auth: "username:password",
  data: {foo: 'bar'}
});
JsonRoutes.add("post", "/api/xyz", function (req, res, next) {
  res.setHeader("Access-Control-Allow-Origin", "*");

  // If we were using OAuth we'd check for an access token 
  // var accessTokenStr = (req.params && req.params.access_token) || (req.query && req.query.access_token);
  // var accessGranted = oAuth2Server.collections.accessToken.findOne({accessToken: accessTokenStr});

  // How can we check for accessGranted using Basic Authentication????

  if (accessGranted) {
    JsonRoutes.sendResult(res, {code: 200});
  } else {
    JsonRoutes.sendResult(res, {code: 401});
  }
});

Is this what simple:rest-accounts-bearer-token is for? I’m thinking… maybe not?

No token auth is pretty different - it looks at a header and matches that with a token in the database. I think you would need to look at the “req” argument and find information about basic auth in there.

1 Like