Skip to content

Commit

Permalink
chore(docs): Add documentation to explain how to support custom fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorahman committed Mar 8, 2024
1 parent 967dd30 commit ea085cf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.1.0
feat:
Support for customizing the login validation fields

## 3.0.0
fix: BREAK Change: change PUT behavior to return 404 when resource not found

Expand Down
30 changes: 30 additions & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ auth:
urlSkip:
- path_without_authentication:
method: http method (post,get,put,patch ou delete)
authFields:
- matricula:
type: int
- celular:
type: string
```

Tags description:
Expand All @@ -140,6 +145,7 @@ enableAdm -> Se habilitado o json_rest_server vai permitir somente requisições
urlUserPermission -> Quando habilitado o enableADM você pode permitir que um usuário simples faça as requisições de POST, PUT, DELETE colocando a url aqui.
unauthorizedStatusCode -> The status to use in case of denied access
urlSkip -> Urls that you don't want to be verified with JWT
authFields(optional) -> Please list the fields that will be used for authentication and their respective types to customize the login.
```

**Example**
Expand All @@ -149,6 +155,12 @@ In the example below the server will not verify the authentication to /user in

Now in the second path **/products/{\*}** , this strange command **{\*}**, is a wilcard, because all the paths in the database.json that use an ID in the url, like **/producs/1**, we need to ignore the url parameter to find the url. With this wilcard we allow to make some dynamc urls to be accessed without authentication

The authFields parameter is **optional**, and it should contain the fields that will be used for authentication. It is necessary to include the **name** of the field and the **data type** as in the example below.

Allowed types in authFields -> "**string**", "**int**", or "**double**"

**Note:** If the authFields parameter is not defined in the *config.yaml*, the Json Rest Server will maintain the default authentication, which uses **"email"** and **"password"**, both as string.

```json
auth:
jwtSecret: cwsMXDtuP447WZQ63nM4dWZ3RppyMl
Expand All @@ -159,6 +171,13 @@ auth:
method: post
- /products/{*}:
method: get
authFields:
- registration:
type: int
- mobile:
type: string
- grade:
type: double

```

Expand All @@ -173,6 +192,17 @@ To login and authenticate you need to make a post request in the url ex: http://
}
```

If you have configured the authFields to customize the login fields, the fields should be sent as they were defined in the config.yaml.

```json
// Example of a custom request with authFields.
{
"registration": 102030,
"mobile": "+5535988881234",
"grade": 8.5
}
```

The Json Rest Server will find in your user's table the email that you sent in database.json, and if it's there you will recieve a json with an access token

```json
Expand Down

0 comments on commit ea085cf

Please sign in to comment.