Apigee Node.js Api Proxy with Basic Authentication

2 0 1,491

This API Proxy provides a sample of a resource protected with Basic Authentication in Apigee as a Node.js app. Source code available from this repo.

Test

Try loading these resources: static resources/images, dynamic resources. This resource is protected with Basic Authentication. Use username 'testUser' and password 'testPass'.

How it works

The following code is the only element that is necessary to protect resources with Basic Authentication. Please keep in mind that you can also leverage Apigee Developer Model to leverage client id and secret on this API proxy. Hint: load variables with Apigee Access. For more details about Basic Authentication with Node.js, check more examples here.

    //app.js
    // Authenticator
    app.use(express.basicAuth(function(user, pass) {
    "use strict";
     return user === 'testUser' && pass === 'testPass';
    }));

Deploy it in your own Org

There are a few way to deploy this API proxy. The easier one is to deploy manually through the UI api-proxy-nodejs-basic-auth.zip stored under the target folder.

The second option is to leverage Apigee Deploy Grunt Plugin. Once it has been deployed on your own org, you can leverage a link similar to the above. https://{org}-{env}.apigee.net/node-basic-auth/tree.jpg

Once you have the plugin installed, just run this command to deploy this API in your org:

$ grunt --env=test --username=$ae_username --password=$ae_password --debug
Version history
Last update:
‎03-29-2015 12:21 PM
Updated by: