couchdb-calculate-session-id

calculates valid CouchDB session IDs using username, salt, secret & timestamp

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
couchdb-calculate-session-id
931.1.36 years ago8 years agoMinified + gzip package size for couchdb-calculate-session-id in KB

Readme

couchdb-calculate-session-id
calculates valid CouchDB session IDs using username, salt, secret & timestamp

Build Status Coverage Status Dependency Status devDependency Status

Example

var calculateSessionId = require('couchdb-calculate-session-id')

var sessionId = calculateSessionId(
  'pat',
  '24eb90e9e1343977b8323857287ffca4',
  '78875068a1979fb910d5d8f37d316aa4',
  1449689785
)

Arguments

<tr>
  <th align="left">Argument</th>
  <th align="left">Type</th>
  <th align="left">Description</th>
</tr>
<th align="left"><strong>username</strong></th>
<td>String</td>
<td><code>name</code> property of <code>\_users</code> doc</td>
<th align="left"><strong>usersalt</strong></th>
<td>String</td>
<td><code>salt</code> property of <code>\_users</code> doc</td>
<th align="left"><strong>serversecret</strong></th>
<td>String</td>
<td><code>couch_httpd_auth.secret</code> of CouchDB configuration</td>
<th align="left"><strong>timestamp</strong></th>
<td>Number</td>
<td>Number of seconds elapsed since 1 January 1970 00:00:00 UTC</td>

How CouchDB does it using Erlang

make_cookie_hash(UserName, Secret, TimeStamp) ->
    SessionData = UserName ++ ":" ++ erlang:integer_to_list(TimeStamp, 16),
    Hash = crypto:sha_mac(Secret, SessionData),
    couch_util:encodeBase64Url(SessionData ++ ":" ++ ?b2l(Hash)).

Credits

All credits due to @christophwitzko, @indutny & @janl: https://gist.github.com/janl/4583f5eb4c0d8216cc5f

License

Apache-2.0