incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alen Mujezinovic <>
Subject Custom `user_ctx` attributes
Date Fri, 03 Dec 2010 17:04:42 GMT
Hey guys

Here's a suggestion about the `user_ctx` record in couch_db.hrl:

We've been working on custom authentication handlers and one issue came
up to pass some custom information into `validate_doc_update`.

We're essentially having a bunch of databases, each of which holds
documents with user information. Now, instead of passing on the user
from the `_users` table as `user_ctx`, we're passing on the actual
user interacting with our application and the current database.

Think of it this way:

    - Request comes in for database `foo`.
    - `Authorization` header is checked against the `_user` database
    - If it is all right, we look at a custom header `X-App-User` which
    is essentially a document id.
    - We look this id up in the database `foo` and get a user document:

        { _id : "bar", roles: [], yadda: 'yadda'}

    - We take the `roles` attribute from that document and pass it
    on as `user_ctx`.

Now, that seems fine. Our problem though is that there are some cases
where we would want to pass on more into the `validate_doc_update` function
than just `` and `user_ctx.roles`.

I went with this problem to #erlang, to ask if there's a way to extend
predefined records with arbitrary attributes, and it turns out that
this is way too hacky - and possibly would lead to maintenance hell
down the road.


    Add another attribute `aux` or whatever to the `user_ctx` record,
    which can be populated with whatever junk one wants to use in

Maybe there is already a way and I'm missing it (didn't look too
closely at the `handler` attribute, figured that is already used for
something internally) - or better ways to do what we're trying. If so,
hints please. :)

Feedback, thoughts? Do you take patches? :)


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message