@@ -14,6 +14,29 @@ var passport = require('passport')
1414 * parameter can be located in an `Authorization` header field, the request
1515 * entity body, or the URL query parameters.
1616 *
17+ * This strategy requires three functions as callbacks, referred to as
18+ * `consumer`, `token` and `validate`.
19+ *
20+ * The `consumer` callback accepts `consumerKey` and must call `done` supplying
21+ * a `consumer` and `consumerSecret`. The strategy will use the secret to
22+ * compute the signature, failing authentication if it does not match the
23+ * request's signature. Note that `consumer` is the authenticating entity of
24+ * this strategy, and will be set by Passport at `req.user` upon success. If an
25+ * exception occured, `err` should be set.
26+ *
27+ * The `token` callback accepts `requestToken` and must call `done` supplying
28+ * a `tokenSecret` and optional `info`. The strategy will use the secret to
29+ * compute the signature, failing authentication if it does not match the
30+ * request's signature. The optional `info` is typically used to carry
31+ * additional authorization details associated with the token (the verifier, for
32+ * example). `info` will be set by Passport at `req.authInfo`, where it can be
33+ * used by later middleware, avoiding the need to re-query a database for the
34+ * same information. If an exception occured, `err` should be set.
35+ *
36+ * The `validate` callback is optional, accepting `timestamp` and `nonce` as a
37+ * means to protect against replay attacks.
38+ *
39+ *
1740 * Note that despite defining a single authentication scheme, OAuth
1841 * authentication serves two distinct purposes:
1942 * 1. Authenticating consumers (aka clients) that are requesting access to
@@ -25,8 +48,8 @@ var passport = require('passport')
2548 * Due to the nature of OAuth, in cases where the consumer is attempting to
2649 * obtain an access token, the credentials will also contain a callback URL or a
2750 * previously issued request token and verifier. This information will be
28- * carried through in `req.authInfo` to be handled by other middleware or routes
29- * as necessary.
51+ * carried through by Passport in `req.authInfo` to be handled by other
52+ * middleware or routes as necessary.
3053 *
3154 * When the consumer is making a request to the request token endpoint,
3255 * `authInfo` will contain the following properties:
@@ -46,6 +69,31 @@ var passport = require('passport')
4669 * and access token URL, as defined by the OAuth specification (aka the
4770 * temporary credential endpoint and token endpoint in RFC 5849).
4871 *
72+ * Examples:
73+ *
74+ * passport.use('consumer', new ConsumerStrategy(
75+ * function(consumerKey, done) {
76+ * Consumer.findByKey({ key: consumerKey }, function (err, consumer) {
77+ * if (err) { return done(err); }
78+ * if (!consumer) { return done(null, false); }
79+ * return done(null, consumer, consumer.secret);
80+ * });
81+ * },
82+ * function(requestToken, done) {
83+ * RequestToken.findOne(requestToken, function (err, token) {
84+ * if (err) { return done(err); }
85+ * if (!token) { return done(null, false); }
86+ * // third argument is optional info. typically used to pass
87+ * // details needed to authorize the request (ex: `scope`)
88+ * return done(null, token.secret, { verifier: token.verifier });
89+ * });
90+ * },
91+ * function(timestamp, nonce, done) {
92+ * // validate the timestamp and nonce as necessary
93+ * done(null, true)
94+ * }
95+ * ));
96+ *
4997 * References:
5098 * - [Temporary Credentials](http://tools.ietf.org/html/rfc5849#section-2.1)
5199 * - [Token Credentials](http://tools.ietf.org/html/rfc5849#section-2.3)
0 commit comments