This repository has been archived by the owner on Oct 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from ValeriyRadchenko/Server
Simple NodeJS server
- Loading branch information
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |