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

Commit 7f7fdf0

Browse files
committed
Merge pull request #11 from AzureADSamples/dev
Big update to support OIDC and cleaning up the sample.
2 parents 4cdfd95 + 3196b16 commit 7f7fdf0

21 files changed

Lines changed: 2049 additions & 701 deletions

README.md

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

3+
<<<<<<< HEAD
4+
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.
5+
=======
36
[![Join the chat at https://gitter.im/AzureADSamples/WebAPI-Nodejs](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/AzureADSamples/WebAPI-Nodejs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
47

58
This Node.js server will give you with a quick and easy way to set up a REST API Service that's integrated with Windows Azure Active Directory for API protection using the OAuth2 protocol. The sample server included in the download are designed to run on any platform.
9+
>>>>>>> master
610
711
This REST API server is built using Restify and MongoDB with the following features:
812

9-
* A node.js server running an REST API interface with JSON using MongoDB as persistant storage
13+
* A node.js server running an REST API interface with JSON using MongoDB as persistent storage
1014
* REST APIs leveraging OAuth2 API protection for endpoints using Windows Azure Active Directory
1115

12-
[Refer to our Wiki](https://github.com/AzureADSamples/WebAPI-Nodejs/wiki) for detailed walkthroughs on how to use this server.
13-
1416
We've released all of the source code for this example in GitHub under an Apache 2.0 license, so feel free to clone (or even better, fork!) and provide feedback on the forums.
1517

16-
## How to Use The Service
17-
18-
This is a simple TODO Server that takes requests through GET and POST and responds with the appropriate JSON objects.
19-
20-
#### To use this without Authentication (for testing the endpoints without Authentication)
21-
22-
$ node server.js
23-
24-
$ curl -isS http://127.0.0.1:8888 | json
25-
HTTP/1.1 200 OK
26-
Connection: close
27-
Content-Type: application/x-www-form-urlencoded
28-
Content-Length: 145
29-
Date: Wed, 29 Jan 2014 03:41:24 GMT
30-
31-
[
32-
"GET /",
33-
"POST /tasks/:name/:task",
34-
"GET /tasks",
35-
"DELETE /tasks",
36-
"PUT /tasks/:name",
37-
"GET /tasks/:name",
38-
"DELETE /tasks/:task"
39-
]
40-
41-
#### To invoke with OAuth2 Authentication (for use with Windows Azure AD)
42-
43-
$ node server.js -m oauth2
4418

4519
## Quick Start
4620

47-
Getting started with the sample is easy. It is configured to run out of the box with minimal setup.
21+
Getting started with the sample is easy. It is configured to run out of the box with minimal setup.
4822

4923
### Step 1: Register a Windows Azure AD Tenant
5024

51-
To use this sample you will need a Windows Azure Active Directory Tenant. If you're not sure what a tenant is or how you would get one, read [What is a Windows Azure AD tenant](http://technet.microsoft.com/library/jj573650.aspx)? or [Sign up for Windows Azure as an organization](http://azure.microsoft.com/en-us/documentation/articles/sign-up-organization/). These docs should get you started on your way to using Windows Azure AD.
25+
To use this sample you will need a Windows Azure Active Directory Tenant. If you're not sure what a tenant is or how you would get one, read [What is an Azure AD tenant](http://technet.microsoft.com/library/jj573650.aspx)? or [Sign up for Azure as an organization](http://azure.microsoft.com/en-us/documentation/articles/sign-up-organization/). These docs should get you started on your way to using Windows Azure AD.
5226

5327
### Step 2: Register your Web API with your Windows Azure AD Tenant
5428

@@ -57,34 +31,52 @@ After you get your Windows Azure AD tenant, add this sample app to your tenant s
5731
### Step 3: Download node.js for your platform
5832
To successfully use this sample, you need a working installation of Node.js.
5933

60-
Install Node.js from [http://nodejs.org](http://nodejs.org).
34+
Install Node.js from [http://nodejs.org](http://nodejs.org).
6135

6236
### Step 4: Install MongoDB on to your platform
6337

64-
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.
38+
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.
39+
40+
Install MongoDB from [http://mongodb.org](http://www.mongodb.org).
6541

66-
Install MongoDB from [http://mongodb.org](http://www.mongodb.org).
42+
**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.
6743

68-
**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
69-
7044

7145
### Step 5: Download the Sample application and modules
7246

7347
Next, clone the sample repo and install the NPM.
7448

7549
From your shell or command line:
7650

77-
* `$ git clone git@github.com:WindowsAzureAD/Azure-AD-TODO-Server-Sample-For-Node.git`
51+
* `$ git clone git@github.com:AzureADSamples/WebAPI-Nodejs.git`
7852
* `$ npm install`
7953

80-
### Step 6: Run the application
54+
**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.
55+
56+
* `$ cd node-server`
57+
* `$ npm install` (yes, again)
58+
59+
### Step 6: Configure your server using config.js
60+
61+
You will need to update the sample to use your values for audienceURI and for the metadata endpoint.
62+
63+
**NOTE:** You may also pass the `issuer:` value if you wish to validate that as well.
64+
65+
### Step 7: Run the application
8166

8267

8368
* `$ cd node-server `
8469
* `$ node server.js`
8570

71+
**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:
72+
73+
* `$ node server.js | bunyan`
74+
75+
### Your done!
8676

87-
### Acknowledgements
77+
You will have a server successfully running on `http://localhost:8888`. Your REST / JSON API Endpoint will be `http://localhost:8888/tasks`
78+
79+
### Acknowledgements
8880

8981
We would like to acknowledge the folks who own/contribute to the following projects for their support of Windows Azure Active Directory and their libraries that were used to build this sample. In places where we forked these libraries to add additional functionality, we ensured that the chain of forking remains intact so you can navigate back to the original package. Working with such great partners in the open source community clearly illustrates what open collaboration can accomplish. Thank you!
9082

@@ -93,11 +85,11 @@ We would like to acknowledge the folks who own/contribute to the following proje
9385
- [Restify](http://mcavage.me/node-restify/) - Restify is a node.js module built specifically to enable you to build correct REST web services. ``` node-restify```
9486
- [Restify-OAuth2](https://github.com/domenic/restify-oauth2) - This package provides a very simple OAuth 2.0 endpoint for the Restify framework. ``` restify-oauth2```
9587
- [node-jwt-simple](https://github.com/hokaccha/node-jwt-simple) - Library for parsing JSON Web Tokens (JWT) ```node-jwt-simple```
88+
- [http-bearer-strategy](https://github.com/jaredhanson/passport-http-bearer) - HTTP Bearer authentication strategy for Passport and Node.js.
9689

9790

9891

9992

10093
## About The Code
10194

10295
Code hosted on GitHub under Apache 2.0 license
103-

0 commit comments

Comments
 (0)