Skip to content
Open
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
18 changes: 18 additions & 0 deletions docs/advance/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ const validFields = [
enumValues: ["abc", "def", "xyz"],
required: true,
},
{ key: "someFunc", type: "function", required: true },
{ key: "someJson", type: "json", required: true },
{ key: "someObjectCollection", type: "object", required: true, isCollection: true },
{
key: "someEnumCollection",
type: "enum",
enumValues: ["abc", "def", "xyz"],
required: true,
isCollection: true
},
];

const toValidate1 = {
Expand All @@ -182,6 +192,10 @@ const toValidate1 = {
someEmail: "email@mail.com",
someArray: ["aaa", "bbb", "ccc"],
someEnum: "def",
someFunc: () => 'bar',
someJson: "{\"foo\":\"bar\",\"isTest\":1}",
someObjectCollection: [{ "foo": "bar", "isTest": 1 }, [{ "another": "object" }],
someEnumCollection: ["def", "abc", "abc"],
};

const validated = validateFields(toValidate1, validFields));
Expand All @@ -198,6 +212,10 @@ const validated = validateFields(toValidate1, validFields));
someEmail: "email@mail.com",
someArray: ["aaa", "bbb", "ccc"],
someEnum: "def",
someFunc: () => 'bar',
someJson: "{\"foo\":\"bar\",\"isTest\":1}",
someObjectCollection: [{ "foo": "bar", "isTest": 1 }, [{ "another": "object" }],
someEnumCollection: ["def", "abc", "abc"],
}
*/
```
Expand Down
133 changes: 0 additions & 133 deletions docs/basics/middleware.md

This file was deleted.

105 changes: 105 additions & 0 deletions docs/basics/middlewares/auth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
These middlewares can be utilized as a layer of authentication before going through your HTTP requests.

## Verify JWT

This middleware will verify any JWT passed to the `Authorization` header of the http request. If the JWT is verified, the decoded JWT can be accesed through `handler.event.decodedJwt`, else a `403` response will be thrown.

**Configuration**

The JWT configuration for your application is located at `src/config/jwt.js`. Or copy [this file](https://raw.githubusercontent.com/reflex-media/lesgo/master/src/config/jwt.js) to that path.

You may also simply update the respective environment files in `config/environments/*` as such:

```apache
# SHA256 JWT secret key, used to verify the token passed to "Authorization" header
JWT_SECRET=""

# Leave empty if you don't want the issuer to be validated
JWT_ISS_SHOULD_VALIDATE=

# Comma-separated list of domains to validate
JWT_ISS_DOMAINS=""

# Leave empty if you don't want the custom claims to be validated
JWT_CUSTOM_CLAIMS_SHOULD_VALIDATE=

# List of custom claims to valdiate.
# Visit https://auth0.com/docs/tokens/jwt-claims for more info
JWT_CUSTOM_CLAIMS_DATA=""
```

**Usage**

```js
import middy from '@middy/core';
import verifyJwtTokenMiddleware from "Middlewares/verifyJwtTokenMiddleware";

const originalHandler = event => {
return event.collection;
};

export const handler = middy(originalHandler);

handler.use(verifyJwtTokenMiddleware());
```

## Basic Auth

This middleware will verify any basic auth passed to the `Authorization` header of the http request. Throws `Middlewares/basicAuthMiddleware::AUTH_INVALID_CLIENT_OR_SECRET_KEY` when a basic auth cannot be found in the clients list configuration.

This middleware can be used together with `clientAuthMiddleware`, as long as `clientAuthMiddleware` is declared first.
This is to allow the middleware to identify the matched `handler.event.platform`.

**Configuration**

The basic auth configuration for your application is located at `src/config/client.js`. Or copy [this file](https://raw.githubusercontent.com/reflex-media/lesgo/master/src/config/client.js) to that path.

**Usage**

```js
import middy from '@middy/core';
import basicAuthMiddleware from "Middlewares/basicAuthMiddleware";

const originalHandler = event => {
return event.collection;
};

export const handler = middy(originalHandler);

handler.use(basicAuthMiddleware());

// or

handler.use(basicAuthMiddleware({
// This is set as an override for Config/client.js when needed
client: {
myApp: {
key: 'myappkeystring',
secret: 'myappsecretstring'
}
}
}));
```

## Client Auth

This middleware will verify key passed to `x-client-id` header of the http request and sets the matched key to `handler.event.platform`. Throws `Middlewares/clientAuthMiddleware::INVALID_CLIENT_ID` when a basic auth cannot be found in the clients list configuration.

**Configuration**

The basic auth configuration for your application is located at `src/config/client.js`. Or copy [this file](https://raw.githubusercontent.com/reflex-media/lesgo/master/src/config/client.js) to that path.

**Usage**

```js
import middy from '@middy/core';
import clientAuthMiddleware from "Middlewares/clientAuthMiddleware";

const originalHandler = event => {
return event.collection;
};

export const handler = middy(originalHandler);

handler.use(clientAuthMiddleware());
```
20 changes: 20 additions & 0 deletions docs/basics/middlewares/event-parsing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
These middlewares can be utilized for parsing data from specific services such as AWS Services, and just instead directly accessing it from a single list of recors inside `handler.event.collection`.

## Normalize SQS Message

This middleware will normalize records coming from sqs message event. The `Records` object in the `handler.event` will be normalized into `handler.event.collection`. This middleware executes _before_ the handler is called.

**Usage**

```js
import middy from '@middy/core';
import normalizeSQSMessage from "Middlewares/normalizeSQSMessage";

const originalHandler = event => {
return event.collection;
};

export const handler = middy(originalHandler);

handler.use(normalizeSQSMessage());
```
Loading