Quick and easy OAuth authorization code grant type sample leveraging Yeoman and Node.js

5 1 1,026

tl;dr: The new OAuth auth code sample is now available as a Yeoman generator here. We've reduced friction for someone to try out auth code grant type with Apigee Edge. I won't rehash the instructions already included in the generator README.

1456-oauth-authcode.gif

@Diego Zuluaga and I presented a workshop at the I Love APIs conference this year. We focused on the authorization code grant type in OAuth 2.0. The sample we used at the conference was largely implemented in Apigee Edge. This was a modification to an already excellent sample. Credits go to @Michael Russo and @wwitman for coding up the original sample that served as a foundation.

One of the big To-Do items we had on our list was to make the sample as easy to install as possible. We leveraged Yeoman and Node.js to make the installation a snap. Inquirer module prompts you for the 5 critical pieces of information, and then the Yeoman generator takes it from there to scaffold the base directory/file structure from templates. Then we leveraged shellJS for synchronized SED and cURL calls.

The end result is that the new sample further reduces the friction to get an authorization code grant type use-case running. Now the person deploying can focus on learning the intricate details of OAuth auth code rather than worry about typos or misunderstandings ('Is this the client ID for the webserver proxy or the login-app?').

Yeoman and Node.js are a solid alternative to shell scripts, so we urge you to give them a try in your next sample or POC. And hey, you don't have to completely remove your shell scripts-- we still use some within the generator (though they may not survive the next few versions 🙂 ).

Special thanks to @Diego Zuluaga for introducing me to Yeoman and for discussing architecture design options along the way.

Comments
terrancedavid
New Member

I am receiving the following error trying to Register a new user in this auth code example:

ReferenceError: "basePath" is not defined.
at /organization/environment/api/node_modules/ejs/lib/ejs.js#237(Function):17
at /organization/environment/api/node_modules/ejs/lib/ejs.js#237(Function):16
at /organization/environment/api/node_modules/ejs/lib/ejs.js:250
at /organization/environment/api/node_modules/ejs/lib/ejs.js:288
at /organization/environment/api/node_modules/ejs/lib/ejs.js:318
at /organization/environment/api/node_modules/ejs-locals/index.js:85
at render (/organization/environment/api/node_modules/express/lib/view.js:128)
at tryRender (/organization/environment/api/node_modules/express/lib/application.js:640)
at render (/organization/environment/api/node_modules/express/lib/application.js:592)
at render (/organization/environment/api/node_modules/express/lib/response.js:971)
at /organization/environment/api/routes/registration.js:27
at handle (/organization/environment/api/node_modules/express/lib/router/layer.js:95)
at next (/organization/environment/api/node_modules/express/lib/router/route.js:137)
at dispatch (/organization/environment/api/node_modules/express/lib/router/route.js:112)
at handle (/organization/environment/api/node_modules/express/lib/router/layer.js:95)
at /organization/environment/api/node_modules/express/lib/router/index.js:281
at process_params (/organization/environment/api/node_modules/express/lib/router/index.js:335)
at next (/organization/environment/api/node_modules/express/lib/router/index.js:275)
at /organization/environment/api/node_modules/body-parser/lib/read.js:130
at invokeCallback (/organization/environment/api/node_modules/raw-body/index.js:262)
at done (/organization/environment/api/node_modules/raw-body/index.js:251)
at onEnd (/organization/environment/api/node_modules/raw-body/index.js:307)
at emit (events.js:92)
at _stream_readable.js:943
at _tickDomainCallback (trireme.js:491)
at _tickFromSpinner (trireme.js:422) Would love some help. :)
Version history
Last update:
‎10-26-2015 05:07 PM
Updated by: