@@ -15,6 +15,29 @@ var passport = require('passport')
1515 * located in an `Authorization` header field, the request entity body, or the
1616 * URL query parameters.
1717 *
18+ * This strategy requires three functions as callbacks, referred to as
19+ * `consumer`, `verify` and `validate`.
20+ *
21+ * The `consumer` callback accepts `consumerKey` and must call `done` supplying
22+ * a `consumer` and `consumerSecret`. The strategy will use the secret to
23+ * compute the signature, failing authentication if it does not match the
24+ * request's signature. If an exception occured, `err` should be set.
25+ *
26+ * The `verify` callback accepts `accessToken` and must call `done` supplying
27+ * a `user`, `tokenSecret` and optional `info`. Note that `user` is the
28+ * authenticating entity of this strategy, and will be set by Passport at
29+ * `req.user` upon success. The strategy will use the secret to compute the
30+ * signature, failing authentication if it does not match the request's
31+ * signature. The optional `info` is typically used to carry additional
32+ * authorization details associated with the token (scope of access, for
33+ * example). `info` will be set by Passport at `req.authInfo`, where it can be
34+ * used by later middleware, avoiding the need to re-query a database for the
35+ * same information. If an exception occured, `err` should be set.
36+ *
37+ * The `validate` callback is optional, accepting `timestamp` and `nonce` as a
38+ * means to protect against replay attacks.
39+ *
40+ *
1841 * Note that despite defining a single authentication scheme, OAuth
1942 * authentication serves two distinct purposes:
2043 * 1. Authenticating consumers (aka clients) that are requesting access to
@@ -37,6 +60,35 @@ var passport = require('passport')
3760 *
3861 * This strategy is inteded to be employed in routes for protected resources.
3962 *
63+ * Examples:
64+ *
65+ * passport.use('token', new TokenStrategy(
66+ * function(consumerKey, done) {
67+ * Consumer.findByKey({ key: consumerKey }, function (err, consumer) {
68+ * if (err) { return done(err); }
69+ * if (!consumer) { return done(null, false); }
70+ * return done(null, consumer, consumer.secret);
71+ * });
72+ * },
73+ * function(accessToken, done) {
74+ * AccessToken.findOne(accessToken, function (err, token) {
75+ * if (err) { return done(err); }
76+ * if (!token) { return done(null, false); }
77+ * Users.findOne(token.userId, function(err, user) {
78+ * if (err) { return done(err); }
79+ * if (!user) { return done(null, false); }
80+ * // fourth argument is optional info. typically used to pass
81+ * // details needed to authorize the request (ex: `scope`)
82+ * return done(null, user, token.secret, { scope: token.scope });
83+ * });
84+ * });
85+ * },
86+ * function(timestamp, nonce, done) {
87+ * // validate the timestamp and nonce as necessary
88+ * done(null, true)
89+ * }
90+ * ));
91+ *
4092 * References:
4193 * - [Authenticated Requests](http://tools.ietf.org/html/rfc5849#section-3)
4294 * - [Accessing Protected Resources](http://oauth.net/core/1.0a/#anchor12)
0 commit comments