Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,13 @@ Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protrac

The workspace includes a playground application that can be used to test out features of the SDK. Run this using `ng serve playground` and browse to http://localhost:4200.

#### Running an express server

An express server can be started by running `npm run server:api`, which can be used to make testing Http Interceptors easier.
The express server exposes a single endpoint at `http://localhost:3001/api/external` that needs to be called with an `Authorization` header containing a token for the corresponding `domain` and `audience`, configurable in [`api-server.js`](api-server.js).

The playground application is preconfigured to call the above endpoint when clicking the `Call external API` button.

## Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
Expand Down
45 changes: 45 additions & 0 deletions api-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const express = require('express');
const cors = require('cors');
const jwt = require('express-jwt');
const jwksRsa = require('jwks-rsa');

const app = express();

const authConfig = {
domain: 'brucke.auth0.com',
audience: 'http://localhost/',
appUri: 'http://localhost:4200',
};

if (!authConfig.domain || !authConfig.audience) {
throw 'Please make sure that auth_config.json is in place and populated';
}

app.use(
cors({
origin: authConfig.appUri,
})
);

const checkJwt = jwt({
secret: jwksRsa.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: `https://${authConfig.domain}/.well-known/jwks.json`,
}),

audience: authConfig.audience,
issuer: `https://${authConfig.domain}/`,
algorithms: ['RS256'],
});

app.get('/api/external', checkJwt, (req, res) => {
res.send({
msg: 'Your access token was successfully validated!',
});
});

const port = process.env.API_SERVER_PORT || 3001;

app.listen(port, () => console.log(`Api started on port ${port}`));
Loading