Skip to content
This repository has been archived by the owner on Oct 16, 2019. It is now read-only.

Commit

Permalink
Merge pull request #32 from ValeriyRadchenko/Server
Browse files Browse the repository at this point in the history
Simple NodeJS server
  • Loading branch information
chenkie authored Oct 25, 2016
2 parents 754d204 + 6c65f59 commit 4594501
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.DS_Store
20 changes: 20 additions & 0 deletions Server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Auth0 Simple NodeJS Server

This is a simple Express server that has two routes:

* **`/ping`**
* **`/secured/ping`**

The intent is to show how to protect the `secured` endpoint with JWT authentication using Auth0.

## Install Dependencies

```bash
npm install
```

## Add Your Auth0 Credentials

If you haven't already done so, [sign up](https://auth0.com/signup) for your free Auth0 account. Once you have the client ID and client secret for your app, replace the argumentts in the `authenticate` middleware within `server.js` with them.

Once your client ID and client secret are set, run the app with `node server.js`. It will be served at `http://localhost:3001`.
12 changes: 12 additions & 0 deletions Server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "auth0-server",
"version": "1.0.0",
"main": "server.js",
"repository": "https://github.com/auth0-samples/auth0-angularjs-sample",
"license": "MIT",
"dependencies": {
"cors": "^2.7.1",
"express": "^4.13.4",
"express-jwt": "^3.4.0"
}
}
26 changes: 26 additions & 0 deletions Server/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var http = require('http');
var express = require('express');
var cors = require('cors');
var app = express();
var jwt = require('express-jwt');

var authenticate = jwt({
secret: new Buffer('YOUR_SECRET', 'base64'),
audience: 'YOUR_CLIENT'
});

app.use(cors());

app.get('/ping', function(req, res) {
res.send(200, {text: "All good. You don't need to be authenticated to call this"});
});

app.get('/secured/ping', authenticate, function(req, res) {
res.send(200, {text: "All good. You only get this message if you're authenticated"});
});

var port = process.env.PORT || 3001;

http.createServer(app).listen(port, function (err) {
console.log('listening in http://localhost:' + port);
});

0 comments on commit 4594501

Please sign in to comment.