Skip to content

Commit c15eba3

Browse files
committed
Clarify comments.
1 parent 89e320e commit c15eba3

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

lib/state/session.js

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
var uid = require('uid2');
22

33
/**
4-
* Creates an instance of `SessionStateProvider`.
4+
* Creates an instance of `SessionStore`.
55
*
6-
* This is the default state provider implementation for the OAuth2Strategy.
7-
* If generates a random state and stores it in `req.session` under the `key`
8-
* provided in the constructor.
6+
* This is the state store implementation for the OAuth2Strategy used when
7+
* the `state` option is enabled. It generates a random state and stores it in
8+
* `req.session` and verifies it when the service provider redirects the user
9+
* back to the application.
910
*
10-
* If no session exists, the provider will throw an error. If you are not using
11-
* sessions, consider using `TokenStateProvider` instead.
11+
* This state store requires session support. If no session exists, an error
12+
* will be thrown.
1213
*
1314
* Options:
1415
*
15-
* - `key` The key in the session under which to store the session state
16+
* - `key` The key in the session under which to store the state
1617
*
1718
* @constructor
1819
* @param {Object} options
@@ -24,10 +25,11 @@ function SessionStore(options) {
2425
}
2526

2627
/**
27-
* Given a request, returns a value to use as state.
28+
* Store request state.
2829
*
29-
* This implementation simply generates a random UID and stores the value in the session
30-
* for validation at a later stage when `verify` is called.
30+
* This implementation simply generates a random string and stores the value in
31+
* the session, where it will be used for verification when the user is
32+
* redirected back to the application.
3133
*
3234
* @param {Object} req
3335
* @param {Function} callback
@@ -44,15 +46,10 @@ SessionStore.prototype.store = function(req, callback) {
4446
};
4547

4648
/**
47-
* Given a request, and the state returned by the OAuth provider, verifies the state.
49+
* Verify request state.
4850
*
49-
* This implementation simply compares the returned state to the one saved in the user's session.
50-
* If they do not match, or no state is saved in the session, the call will fail.
51-
* If there is no session, the call will return an error.
52-
*
53-
* The callback signature has two values (`err`, `failureCode`). On success, these are both
54-
* undefined. On error, only `err` is definied and on failure, err will contain the failure object
55-
* while `failureCode` will contain the failure code.
51+
* This implementation simply compares the state parameter in the request to the
52+
* value generated earlier and stored in the session.
5653
*
5754
* @param {Object} req
5855
* @param {String} providedState
@@ -84,7 +81,5 @@ SessionStore.prototype.verify = function(req, providedState, callback) {
8481
return callback(null, true);
8582
};
8683

87-
/**
88-
* Expose `SessionStateProvider`.
89-
*/
84+
// Expose constructor.
9085
module.exports = SessionStore;

0 commit comments

Comments
 (0)