classy-org/classy-node

individual oauth not working as in example

Closed this issue · 3 comments

I'm testing out Classy Login, and in order to troubleshoot some code tried to use classy-node's oauth functions. My code is almost exactly the same as the example, but I'm getting a "Method not allowed" response when attempting to get a user auth token.

const Classy = require('classy-node');

const classy = new Classy({ clientId: 'CLIENT_ID', clientSecret: 'CLIENT_SECRET' });

const app = classy.app();

app.then((appResponse) => {

    classy.oauth.auth({
        username: 'USERNAME',
        password: 'P@SSW0RD',
        token: 'app'
    }).then(authResponse => {
        console.log(authResponse);
    }).catch(authErr => {
        console.error(authErr);
    })
    
})

The relevant debug output looks like this:

// request 1 (for the app token) was successful.

{ debugId: 2,
  uri: 'https://api.classy.org//oauth2/auth',
  method: 'POST',
  headers:
   { Accept: 'application/json',
     'Content-Type': 'application/x-www-form-urlencoded',
     Authorization: 'Bearer HIDDEN',
     host: 'api.classy.org',
     'content-length': 146 },
  body: 'username=USERNAME&password=P@SSW0RD&token=app&grant_type=password&client_id=HIDDEN&client_secret=HIDDEN' }
{ debugId: 2,
  headers:
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     date: 'Mon, 17 Jul 2017 02:12:55 GMT',
     server: 'nginx',
     via: 'kong/0.9.3',
     'x-kong-proxy-latency': '2',
     'x-kong-upstream-latency': '40',
     'content-length': '30',
     connection: 'Close' },
  statusCode: 405,
  body: '{"error":"Method not allowed"}' }
PGBI commented

@crismanNoble This example should be removed from the readme file. Oauth2 with password grant method is not and will not be made available to third party apps. Hence the response ("method not allowed").

To get a member token, third party apps will have to use the oauth2 authorization grant method (aka "3-legged oauth2 method" where a user is sent to login.classy.org and grants permissions to a third party app). The documentation on how to get a member token using this grant method is not released yet.

@PGBI FWIW, that's the answer I was hoping for. As a 3rd party I was always surprised that there was an option to auth with the user's credentials. I've been testing Classy Login (3-legged oauth2 method) and it is precisely how I would want to authenticate an end user to my apps.

Thanks for following up @PGBI and thanks for the great catch @dpfavand . I've removed the outdated example from our README.