Skip to content

Commit

Permalink
[Docs] Upgrade translations
Browse files Browse the repository at this point in the history
  • Loading branch information
LoicPoullain committed Sep 6, 2023
1 parent 7d5a770 commit 01521a0
Show file tree
Hide file tree
Showing 44 changed files with 225 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,38 @@ export class AppController implements IAppController {

On every request, the controller method is called with a `Context` object. This context is unique and specific to the request.

It has four properties:
It has seven properties:

| Name | Type | Description |
| --- | --- | --- |
| `request` | `Request` | Gives information about the HTTP request. |
| `state` | `{ [key: string]: any }` | Object which can be used to forward data accross several hooks (see [Hooks](./hooks.md)). |
| `user` | `{ [key: string]: any }\|null` | The current user (see [Authentication](../authentication/quick-start.md)). |
| `session`| `Session\|null` | The session object if you use sessions. |
| `user` | `{ [key: string]: any }`\|`null` | The current user (see [Authentication](../authentication/quick-start.md)). |
| `session`| `Session`\|`null` | The session object if you use sessions. |
| `files` | `FileList` | A list of file paths or buffers if you uploaded files (see [Upload and download files](../common/file-storage/upload-and-download-files.md)). |
| `controllerName` | `string` | The name of the controller class. |
| `controllerMethodName` | `string` | The name of the controller method. |

The types of the `user` and `state` properties are generic. You override their types if needed:

```typescript
import { Context, Get } from '@foal/core';

interface State {
foo: string;
}

interface User {
id: string;
}

export class ProductController {
@Get('/')
getProducts(ctx: Context<User, State>) {
// ...
}
}
```

### HTTP Requests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ export class ApiController {

*auth.controller.ts*
```typescript

import { setAuthCookie, removeAuthCookie } from '@foal/jwt';

export class AuthController {

@Post('/login')
Expand Down Expand Up @@ -793,4 +796,4 @@ export class ApiController {
| The audience is not expected. | 401 | `{ code: 'invalid_token', description: 'jwt audience invalid. expected: xxx' }` | error="invalid_token", error_description="jwt audience invalid. expected: xxx"
| The issuer is not expected. | 401 | `{ code: 'invalid_token', description: 'jwt issuer invalid. expected: xxx' }` | error="invalid_token", error_description="jwt issuer invalid. expected: xxx"
| There is no subject claim and `options.user` is defined. | 401 | `{ code: 'invalid_token', description: 'The token must include a subject which is the id of the user.' }` | error="invalid_token", error_description="The token must include a subject which is the id of the user."
| `options.user` is defined and no user was found from its value (function). | 401 | `{ code: 'invalid_token', description: 'The token subject does not match any user.' }` | error="invalid_token", error_description="The token subject does not match any user."
| `options.user` is defined and no user was found from its value (function). | 401 | `{ code: 'invalid_token', description: 'The token subject does not match any user.' }` | error="invalid_token", error_description="The token subject does not match any user."
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const isEqual = await verifyPassword(plainTextPassword, passwordHash);

## Password Upgrading

> *This feature is available from version 2.11 onwards.*
The PBKDF2 algorithm uses a number of iterations to hash passwords. This work factor is deliberate and slows down potential attackers, making attacks against hashed passwords more difficult.

As computing power increases, the number of iterations must also increase. This is why the latest versions of Foal use a higher number of iterations.
Expand Down Expand Up @@ -58,3 +56,16 @@ if (passwordHashNeedsToBeRefreshed(user.password)) {

// Log the user in.
```


## Forbid Overly Common Passwords

```
npm install @foal/password
```

To prevent users from using very weak passwords such as `123456` or `password`, you can call the `isCommon` function. This utility checks if the given password is part of the 10000 most common passwords listed [here](https://github.com/danielmiessler/SecLists/blob/master/Passwords/Common-Credentials/10-million-password-list-top-10000.txt).

```typescript
const isPasswordTooCommon = await isCommon(password);
```
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = {
#### TypeORMStore

```
npm install typeorm @foal/typeorm
npm install typeorm@0.3.17 @foal/typeorm
```

This store uses the default TypeORM connection whose configuration is usually specified in `config/default.{json|yml|js}`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ FoalTS provides several commands to help you build and develop your app.
| `npm run dev` | Build the source code and start the server. If a file changes then the code is rebuilt and the server reloads. This is usually **the only command that you need during development** |
| `npm run build` | Build the app code located in the `src/` directory (test files are ignored). |
| `npm run start` | Start the server from the built files. |
| `foal upgrade [version]` | Upgrade all local `@foal/*` dependencies and dev dependencies to the given version. If no version is provided, then the command upgrades to the latest version of Foal. An additional flag `--no-install` can be provided to not trigger the npm or yarn installation. |
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ title: GraphQL

> The below document assumes that you have a basic knowledge of GraphQL.
To use GraphQL with FoalTS, you need to install the packages `graphql` and `@foal/graphql`. The first one is maintained by the GraphQL community and parses and resolves queries. The second is specific to FoalTS and allows you to configure a controller compatible with common GraphQL clients ([graphql-request](https://www.npmjs.com/package/graphql-request), [Apollo Client](https://www.apollographql.com/docs/react/), etc), load type definitions from separate files or handle errors thrown in resolvers.
To use GraphQL with FoalTS, you need to install the packages `graphql` and `@foal/graphql`. The first one is maintained by the GraphQL community and parses and resolves queries. The second is specific to FoalTS and allows you to configure a controller compatible with common GraphQL clients ([graphql-request](https://www.npmjs.com/package/graphql-request), etc), load type definitions from separate files or handle errors thrown in resolvers.

```bash
npm install graphql@15 @foal/graphql
# OR
npm install graphql@14 @foal/graphql
npm install graphql@16 @foal/graphql
```

## Basic Usage

The main component of the package is the abstract `GraphQLController`. Inheriting this class allows you to create a controller that is compatible with common GraphQL clients ([graphql-request](https://www.npmjs.com/package/graphql-request), [Apollo Client](https://www.apollographql.com/docs/react/), etc) or any client that follows the HTTP specification defined [here](https://graphql.org/learn/serving-over-http/).
The main component of the package is the abstract `GraphQLController`. Inheriting this class allows you to create a controller that is compatible with common GraphQL clients ([graphql-request](https://www.npmjs.com/package/graphql-request), etc) or any client that follows the HTTP specification defined [here](https://graphql.org/learn/serving-over-http/).

Here is an example on how to use it with a simple schema and resolver.

Expand Down Expand Up @@ -403,17 +401,6 @@ export class ApiController extends GraphQLController {

## Using TypeGraphQL


:::info

TypeGraphQL requires version 15 of the `graphql` package:

```bash
npm install graphql@15
```

:::

> *[TypeGraphQL](https://typegraphql.com/) is a library that allows you to create GraphQL schemas and resolvers with TypeScript classes and decorators.*
You can use TypeGraphQL by simply calling its `buildSchema` function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,6 @@ export class ApiController {

> The `@ApiDefineXXX` decorators can be added to any controllers or methods but they always define components in the global scope of the API the controller belongs to.

--

> The schemas defined with these decorators can also be re-used in the `@ValidateXXX` hooks.
> ```typescript
> const productSchema = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ validate(post).then(errors => { // errors is an array of validation errors
### Usage with a Hook

```
npm install class-transformer class-validator @foal/typestack
npm install class-transformer@0.5 class-validator@0.14 @foal/typestack
```

If you want to use it within a hook to validate request bodies, you can install the package `@foal/typestack` for this. It provides a `@ValidateBody` hook that validates the body against a given validator. This body is also unserialized and turned into an instance of the class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ Testing WebSocket controllers and hooks is very similar to testing their HTTP eq
This example shows how to manage multiple node servers using a redis adapter.

```bash
npm install @socket.io/redis-adapter@7 redis@4
npm install socket.io-adapter @socket.io/redis-adapter@8 redis@4
```

*src/index.ts*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ A collection of official and unofficial libraries and resources about Foal.
- [@foal/jwks-rsa](https://www.npmjs.com/package/@foal/jwks-rsa): retrieve RSA signing keys from a JWKS endpoint.
- [@foal/jwt](https://www.npmjs.com/package/@foal/jwt): authenticate users with JWT.
- [@foal/mongodb](https://www.npmjs.com/package/@foal/mongodb): session store for MongoDB.
- [@foal/password](https://www.npmjs.com/package/@foal/password): hash, salt and check passwords.
- [@foal/redis](https://www.npmjs.com/package/@foal/redis): session store for redis.
- [@foal/social](https://www.npmjs.com/package/@foal/social): authenticate users with Facebook, Github, Google and LinkedIn.
- [@foal/storage](https://www.npmjs.com/package/@foal/storage): manage file upload and storage in local and in the Cloud.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ FoalTS supports officially the following databases:
| PostgreSQL | 9.6+ ([Version Policy](https://www.postgresql.org/support/versioning/)) | `pg@8` |
| MySQL | 5.7+ ([Version Policy](https://en.wikipedia.org/wiki/MySQL#Release_history)) | `mysql@2` |
| SQLite | 3 | `sqlite3@5` |
| MongoDB | 4.0+ ([Version Policy](https://www.mongodb.com/support-policy)) | `mongodb@3` |
| MongoDB | 4.0+ ([Version Policy](https://www.mongodb.com/support-policy)) | `mongodb@5` |

## Use with FoalTS

Expand All @@ -63,7 +63,7 @@ When creating a new project, an `SQLite` database is used by default as it does
### Packages

```
npm install typeorm @foal/typeorm
npm install typeorm@0.3.17 @foal/typeorm
```

Two packages are required to use TypeORM with FoalTS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ foal createapp my-app --mongodb
## Configuration

```
npm install mongodb
npm install mongodb@5
```

<Tabs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ If you use cookies, make sure to let them only be sent to the server when the re

```yaml
settings:
// If you use sessions
# If you use sessions
session:
cookie:
secure: true
// If you use JWT
# If you use JWT
jwt:
cookie:
secure: true
# If you use social authentication
social:
cookie:
secure: true
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,38 @@ export class AppController implements IAppController {

On every request, the controller method is called with a `Context` object. This context is unique and specific to the request.

It has four properties:
It has seven properties:

| Name | Type | Description |
| --- | --- | --- |
| `request` | `Request` | Gives information about the HTTP request. |
| `state` | `{ [key: string]: any }` | Object which can be used to forward data accross several hooks (see [Hooks](./hooks.md)). |
| `user` | `{ [key: string]: any }\|null` | The current user (see [Authentication](../authentication/quick-start.md)). |
| `session`| `Session\|null` | The session object if you use sessions. |
| `user` | `{ [key: string]: any }`\|`null` | The current user (see [Authentication](../authentication/quick-start.md)). |
| `session`| `Session`\|`null` | The session object if you use sessions. |
| `files` | `FileList` | A list of file paths or buffers if you uploaded files (see [Upload and download files](../common/file-storage/upload-and-download-files.md)). |
| `controllerName` | `string` | The name of the controller class. |
| `controllerMethodName` | `string` | The name of the controller method. |

The types of the `user` and `state` properties are generic. You override their types if needed:

```typescript
import { Context, Get } from '@foal/core';

interface State {
foo: string;
}

interface User {
id: string;
}

export class ProductController {
@Get('/')
getProducts(ctx: Context<User, State>) {
// ...
}
}
```

### HTTP Requests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ export class ApiController {

*auth.controller.ts*
```typescript

import { setAuthCookie, removeAuthCookie } from '@foal/jwt';

export class AuthController {

@Post('/login')
Expand Down Expand Up @@ -793,4 +796,4 @@ export class ApiController {
| The audience is not expected. | 401 | `{ code: 'invalid_token', description: 'jwt audience invalid. expected: xxx' }` | error="invalid_token", error_description="jwt audience invalid. expected: xxx"
| The issuer is not expected. | 401 | `{ code: 'invalid_token', description: 'jwt issuer invalid. expected: xxx' }` | error="invalid_token", error_description="jwt issuer invalid. expected: xxx"
| There is no subject claim and `options.user` is defined. | 401 | `{ code: 'invalid_token', description: 'The token must include a subject which is the id of the user.' }` | error="invalid_token", error_description="The token must include a subject which is the id of the user."
| `options.user` is defined and no user was found from its value (function). | 401 | `{ code: 'invalid_token', description: 'The token subject does not match any user.' }` | error="invalid_token", error_description="The token subject does not match any user."
| `options.user` is defined and no user was found from its value (function). | 401 | `{ code: 'invalid_token', description: 'The token subject does not match any user.' }` | error="invalid_token", error_description="The token subject does not match any user."
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const isEqual = await verifyPassword(plainTextPassword, passwordHash);

## Password Upgrading

> *This feature is available from version 2.11 onwards.*
The PBKDF2 algorithm uses a number of iterations to hash passwords. This work factor is deliberate and slows down potential attackers, making attacks against hashed passwords more difficult.

As computing power increases, the number of iterations must also increase. This is why the latest versions of Foal use a higher number of iterations.
Expand Down Expand Up @@ -58,3 +56,16 @@ if (passwordHashNeedsToBeRefreshed(user.password)) {

// Log the user in.
```


## Forbid Overly Common Passwords

```
npm install @foal/password
```

To prevent users from using very weak passwords such as `123456` or `password`, you can call the `isCommon` function. This utility checks if the given password is part of the 10000 most common passwords listed [here](https://github.com/danielmiessler/SecLists/blob/master/Passwords/Common-Credentials/10-million-password-list-top-10000.txt).

```typescript
const isPasswordTooCommon = await isCommon(password);
```
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = {
#### TypeORMStore

```
npm install typeorm @foal/typeorm
npm install typeorm@0.3.17 @foal/typeorm
```

This store uses the default TypeORM connection whose configuration is usually specified in `config/default.{json|yml|js}`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ In addition to traditional password authentication, Foal provides services to au
- Google
- Facebook
- Github
- LinkedIn
- Linkedin
- Twitter

If your provider is not listed here but supports OAuth 2.0, then you can still [extend the `AbstractProvider`](#custom-provider) class to integrate it or use a [community provider](#community-providers) below.
Expand Down Expand Up @@ -571,11 +571,11 @@ There are no community providers available yet! If you want to share one, feel f
| `AuthorizationError` | The authorization server returns an error. This can happen when a user does not give consent on the provider page. |
| `UserInfoError` | Thrown in `AbstractProvider.getUserFromTokens` if the request to the resource server is unsuccessful. |

## Cookie options
## Security

### HTTPS

When deploying the application to production, your application must use HTTPS. The `social.cookie.secure` option must be enabled in order to transmit the state cookie only when the request is transmitted through a secure channel (HTTPS).
When deploying the application, you application must use HTTPS.

*production.yml*
```yaml
Expand All @@ -588,14 +588,3 @@ settings:
# Your redirect URI in production
redirectUri: 'https://example.com/signin/google/callback'
```
### Custom domain
To support authentication via different subdomains, you can set the domain of the state cookie with the `social.cookie.domain` option.

```yaml
settings:
social:
cookie:
domain: foalts.org
```
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class ApiController {
}
```

## Create an entity
## Create an entity

```shell
foal g entity <name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ FoalTS provides several commands to help you build and develop your app.
| `npm run dev` | Build the source code and start the server. If a file changes then the code is rebuilt and the server reloads. This is usually **the only command that you need during development** |
| `npm run build` | Build the app code located in the `src/` directory (test files are ignored). |
| `npm run start` | Start the server from the built files. |
| `foal upgrade [version]` | Upgrade all local `@foal/*` dependencies and dev dependencies to the given version. If no version is provided, then the command upgrades to the latest version of Foal. An additional flag `--no-install` can be provided to not trigger the npm or yarn installation. |
Loading

0 comments on commit 01521a0

Please sign in to comment.