1
1
var uid = require ( 'uid2' ) ;
2
2
3
3
/**
4
- * Creates an instance of `SessionStateProvider `.
4
+ * Creates an instance of `SessionStore `.
5
5
*
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.
9
10
*
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 .
12
13
*
13
14
* Options:
14
15
*
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
16
17
*
17
18
* @constructor
18
19
* @param {Object } options
@@ -24,10 +25,11 @@ function SessionStore(options) {
24
25
}
25
26
26
27
/**
27
- * Given a request, returns a value to use as state.
28
+ * Store request state.
28
29
*
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.
31
33
*
32
34
* @param {Object } req
33
35
* @param {Function } callback
@@ -44,15 +46,10 @@ SessionStore.prototype.store = function(req, callback) {
44
46
} ;
45
47
46
48
/**
47
- * Given a request, and the state returned by the OAuth provider, verifies the state.
49
+ * Verify request state.
48
50
*
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.
56
53
*
57
54
* @param {Object } req
58
55
* @param {String } providedState
@@ -84,7 +81,5 @@ SessionStore.prototype.verify = function(req, providedState, callback) {
84
81
return callback ( null , true ) ;
85
82
} ;
86
83
87
- /**
88
- * Expose `SessionStateProvider`.
89
- */
84
+ // Expose constructor.
90
85
module . exports = SessionStore ;
0 commit comments