Skip to content
This repository was archived by the owner on Feb 26, 2020. It is now read-only.

Commit 3a9f311

Browse files
committed
Update to README for new customers
1 parent e742263 commit 3a9f311

6 files changed

Lines changed: 42 additions & 24 deletions

File tree

README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Windows Azure Active Directory Sample REST API Service for Node.js using MongoDB and Restify
22

3-
This Node.js server will give you with a quick and easy way to set up a REST API Service that's integrated with Azure Active Directory for API protection using the OAuth2 protocol with bearer tokens. The sample server included in the download are designed to run on any platform.
3+
This Node.js server will give you with a quick and easy way to set up a REST API Service that's integrated with Azure Active Directory for API protection. It uses the OAuth2 protocol with bearer tokens. The sample server included in the download are designed to run on any platform.
44

55
This REST API server is built using Restify and MongoDB with the following features:
66

@@ -29,11 +29,11 @@ Install Node.js from [http://nodejs.org](http://nodejs.org).
2929

3030
### Step 4: Install MongoDB on to your platform
3131

32-
To successfully use this sample, you must have a working installation of MongoDB. We will use MongoDB to make our REST API persistant across server instances.
32+
To successfully use this sample, you must have a working installation of MongoDB. We will use MongoDB to make our REST API persistent across server instances.
3333

3434
Install MongoDB from [http://mongodb.org](http://www.mongodb.org).
3535

36-
**NOTE:** This walkthrough assumes that you use the default installation and server endpoints for MongoDB, which at the time of this writing is: mongodb://localhost
36+
**NOTE:** This walkthrough assumes that you use the default installation and server endpoints for MongoDB, which at the time of this writing is: mongodb://localhost. This should work locally without any configuration changes if you run this sample on the same machine as you've installed and ran mongodb.
3737

3838

3939
### Step 5: Download the Sample application and modules
@@ -45,12 +45,30 @@ From your shell or command line:
4545
* `$ git clone git@github.com:AzureADSamples/WebAPI-Nodejs.git`
4646
* `$ npm install`
4747

48-
### Step 6: Run the application
48+
**Did you get an error?:** Restify provides a powerful mechanism to trace REST calls using DTrace. However, many operating systems do not have DTrace available. You can safely ignore these errors.
49+
50+
* `$ cd node-server`
51+
* `$ npm install` (yes, again)
52+
53+
### Step 6: Configure your server using config.js
54+
55+
You will need to update the sample to use your values for audienceURI and for the metadata endpoint.
56+
57+
**NOTE:** You may also pass the `issuer:` value if you wish to validate that as well.
58+
59+
### Step 7: Run the application
4960

5061

5162
* `$ cd node-server `
5263
* `$ node server.js`
5364

65+
**Is the server output hard to understand?:** We use `bunyan` for logging in this sample. The console won't make much sense to you unless you also install bunyan and run the server like above but pipe it through the bunyan binary:
66+
67+
* `$ node server.js | bunyan`
68+
69+
### Your done!
70+
71+
You will have a server successfully running on `http://localhost:8888`. Your REST / JSON API Endpoint will be `http://localhost:8888/tasks`
5472

5573
### Acknowledgements
5674

node-server/app.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
var options = {
3939
// The URL of the metadata document for your app. We will put the keys for token validation from the URL found in the jwks_uri tag of the in the metadata.
4040
identityMetadata: config.creds.identityMetadata,
41-
// issuer: config.creds.issuer,
41+
// issuer: config.creds.issuer,
4242
audience: config.creds.audience
4343

4444
};
@@ -317,7 +317,7 @@ var server = restify.createServer({
317317
if (err) { return done(err); }
318318
if (!user) {
319319
// "Auto-registration"
320-
log.info('User was added automatically as they were new. Their sub is: ', token.sub)
320+
log.info('User was added automatically as they were new. Their sub is: ', token.sub);
321321
users.push(token);
322322
owner = token.sub;
323323
return done(null, token);
@@ -374,13 +374,13 @@ var server = restify.createServer({
374374

375375
server.listen(serverPort, function() {
376376

377-
var consoleMessage = '\n Windows Azure Active Directory Tutorial'
378-
consoleMessage += '\n +++++++++++++++++++++++++++++++++++++++++++++++++++++'
377+
var consoleMessage = '\n Windows Azure Active Directory Tutorial';
378+
consoleMessage += '\n +++++++++++++++++++++++++++++++++++++++++++++++++++++';
379379
consoleMessage += '\n %s server is listening at %s';
380380
consoleMessage += '\n Open your browser to %s/tasks\n';
381-
consoleMessage += '+++++++++++++++++++++++++++++++++++++++++++++++++++++ \n'
382-
consoleMessage += '\n !!! why not try a $curl -isS %s | json to get some ideas? \n'
383-
consoleMessage += '+++++++++++++++++++++++++++++++++++++++++++++++++++++ \n\n'
381+
consoleMessage += '+++++++++++++++++++++++++++++++++++++++++++++++++++++ \n';
382+
consoleMessage += '\n !!! why not try a $curl -isS %s | json to get some ideas? \n';
383+
consoleMessage += '+++++++++++++++++++++++++++++++++++++++++++++++++++++ \n\n';
384384

385385
//log.info(consoleMessage, server.name, server.url, server.url, server.url);
386386

node-server/config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Don't commit this file to your public repos. This config is for first-run
22
exports.creds = {
33
mongoose_auth_local: 'mongodb://localhost/tasklist', // Your mongo auth uri goes here
4-
audience: 'https://com.microsoft.windowsazure.activedirectory.samples',
5-
identityMetadata: 'https://login.microsoftonline.com/hypercubeb2c.onmicrosoft.com/.well-known/openid-configuration?p=b2c_1_B2CSI' // For using Microsoft you should never need to change this.
6-
}
4+
audience: 'https://localhost:8888', // the Audience is the App URL when you registered the application.
5+
identityMetadata: 'https://login.microsoftonline.com/hypercubeb2c.onmicrosoft.com/.well-known/openid-configuration?p=b2c_1_B2CSI' // Replace the text after p= with your specific policy.
6+
};

node-server/lib/passport-azure-ad/metadata.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ Metadata.prototype.fetch = function(callback) {
205205
});
206206
},
207207
function(body, next){
208-
if(self.authtype == "saml" || self.authtype == "wsfed") {
208+
if(self.authtype === "saml" || self.authtype === "wsfed") {
209209
// parse the AAD Federation metadata xml
210210
var parser = new xml2js.Parser({explicitRoot:true});
211211
// Note: xml responses from Azure AAD have a leading \ufeff which breaks xml2js parser!
@@ -214,7 +214,7 @@ Metadata.prototype.fetch = function(callback) {
214214
next(err);
215215

216216
});
217-
} else if(self.authtype == "oidc") {
217+
} else if(self.authtype === "oidc") {
218218
log.info("Parsing JSON retreived from the endpoint");
219219
self.metadata = JSON.parse(body);
220220
next(null);
@@ -224,15 +224,15 @@ Metadata.prototype.fetch = function(callback) {
224224
},
225225
function(next){
226226

227-
console.log('updating metadata...');
227+
log.info('updating metadata...');
228228

229-
if(self.authtype == "saml") {
229+
if(self.authtype === "saml") {
230230
self.updateSamlMetadata(self.metatdata, next);
231231
}
232-
else if(self.authtype == "wsfed") {
232+
else if(self.authtype === "wsfed") {
233233
self.updateWsfedMetadata(self.metatdata, next);
234234
}
235-
else if(self.authtype == "oidc") {
235+
else if(self.authtype === "oidc") {
236236
self.updateOidcMetadata(self.metadata, next);
237237
}
238238
},

node-server/lib/passport-azure-ad/oidcstrategy.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ if(options.identityMetadata) {
106106
}
107107

108108
if (!options.certificate && !options.identityMetadata) {
109-
log.warn("No options was presented to Strategy as required.")
109+
log.warn("No options was presented to Strategy as required.");
110110
throw new TypeError('OIDCBearerStrategy requires either a PEM encoded public key or a metadata location that contains cert data for RSA and ECDSA callback.');
111111
}
112112

@@ -143,7 +143,7 @@ if (!options.certificate && !options.identityMetadata) {
143143

144144

145145
var decoded = jws.decode(token);
146-
if (decoded == null) {
146+
if (decoded === null) {
147147
done(null, false, "Invalid JWT token.");
148148
}
149149

@@ -198,7 +198,7 @@ var decoded = jws.decode(token);
198198
var opts = {};
199199
opts.passReqToCallback = true;
200200

201-
console.log('Req: ' + options.passReqToCallback);
201+
log.info('Req: ' + options.passReqToCallback);
202202

203203
BearerStrategy.call(this, options, jwtVerify);
204204

node-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
"assert-plus": "*",
1212
"passport": "*"
1313
}
14-
}
14+
}

0 commit comments

Comments
 (0)