Repository: auth0/node-auth0 (ts)

Issue:
Multiple errors in AuthenticationClient.passwordGrant documentation
* the example calls `auth0.oauth.token` instead of `auth0.passwordGrant` (I don't think `auth0.oauth.token` even exists anymore?)
* the example includes `scope` and `client_id` in the call, but the `userData` parameter documentation doesn't mention these fields
* does the `AuthenticationClient` itself need to be authorized to access the API before it can be used to log users in?

I was only able to get `passwordGrant` to work by including the `client_id` and `client_secret` fields in the `userData` object.  (Since I created the `AuthenticationClient` with the client id and secret, why aren't they passed in automatically?)

Pull request description:
Add client secret to passwordGrant
Should fix #210 and #195

Signed-off-by: petetnt <pete.a.nykanen@gmail.com>

Patch:
diff --git a/src/auth/OAuthAuthenticator.js b/src/auth/OAuthAuthenticator.js
index 5dc7e6e60..156c2f4b1 100644
--- a/src/auth/OAuthAuthenticator.js
+++ b/src/auth/OAuthAuthenticator.js
@@ -151,6 +151,7 @@ OAuthAuthenticator.prototype.passwordGrant = function (userData, cb) {
   };
   var defaultFields = {
     client_id: this.clientId,
+    client_secret: this.clientSecret,
     grant_type: 'password'
   };
   var data = extend(defaultFields, userData);


Test patch:
diff --git a/test/auth/oauth.tests.js b/test/auth/oauth.tests.js
index 2b7dedcd3..54ec2025f 100644
--- a/test/auth/oauth.tests.js
+++ b/test/auth/oauth.tests.js
@@ -375,6 +375,26 @@ describe('OAuthAuthenticator', function () {
         .catch(done);
     });
 
+    it('should include the Auth0 client secret in the request', function (done) {
+      nock.cleanAll();
+
+      var request = nock(API_URL)
+        .post(path, function (body) {
+          return body.client_secret === CLIENT_SECRET;
+        })
+        .reply(200);
+
+      this
+        .authenticator
+        .passwordGrant(userData)
+        .then(function () {
+          expect(request.isDone())
+            .to.be.true;
+
+          done();
+        })
+        .catch(done);
+    });
 
     it('should allow the user to specify the realm', function (done) {
       nock.cleanAll();