You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2020. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+22-4Lines changed: 22 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
#Windows Azure Active Directory Sample REST API Service for Node.js using MongoDB and Restify
2
2
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.
4
4
5
5
This REST API server is built using Restify and MongoDB with the following features:
6
6
@@ -29,11 +29,11 @@ Install Node.js from [http://nodejs.org](http://nodejs.org).
29
29
30
30
### Step 4: Install MongoDB on to your platform
31
31
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.
33
33
34
34
Install MongoDB from [http://mongodb.org](http://www.mongodb.org).
35
35
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.
37
37
38
38
39
39
### Step 5: Download the Sample application and modules
@@ -45,12 +45,30 @@ From your shell or command line:
**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
49
60
50
61
51
62
*`$ cd node-server `
52
63
*`$ node server.js`
53
64
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`
Copy file name to clipboardExpand all lines: node-server/app.js
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,7 @@
38
38
varoptions={
39
39
// 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.
40
40
identityMetadata: config.creds.identityMetadata,
41
-
// issuer: config.creds.issuer,
41
+
// issuer: config.creds.issuer,
42
42
audience: config.creds.audience
43
43
44
44
};
@@ -317,7 +317,7 @@ var server = restify.createServer({
317
317
if(err){returndone(err);}
318
318
if(!user){
319
319
// "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);
321
321
users.push(token);
322
322
owner=token.sub;
323
323
returndone(null,token);
@@ -374,13 +374,13 @@ var server = restify.createServer({
374
374
375
375
server.listen(serverPort,function(){
376
376
377
-
varconsoleMessage='\n Windows Azure Active Directory Tutorial'
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.
log.warn("No options was presented to Strategy as required.")
109
+
log.warn("No options was presented to Strategy as required.");
110
110
thrownewTypeError('OIDCBearerStrategy requires either a PEM encoded public key or a metadata location that contains cert data for RSA and ECDSA callback.');
111
111
}
112
112
@@ -143,7 +143,7 @@ if (!options.certificate && !options.identityMetadata) {
143
143
144
144
145
145
vardecoded=jws.decode(token);
146
-
if(decoded==null){
146
+
if(decoded===null){
147
147
done(null,false,"Invalid JWT token.");
148
148
}
149
149
@@ -198,7 +198,7 @@ var decoded = jws.decode(token);
0 commit comments