Skip to content

Commit

Permalink
docs: Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
igorlukanin authored and mcheshkov committed Aug 20, 2024
1 parent 6a65183 commit 2eb0531
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions docs/pages/reference/configuration/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1079,18 +1079,14 @@ environment documentation][ref-exec-environment-globals].

### `check_auth`

Used in both REST and WebSockets API.
Used in the [REST API][ref-rest-api]. Default implementation parses the [JSON
Web Token][link-jwt] in the `Authorization` header, verifies it, and sets its
payload to the `securityContext`. [Read more][ref-sec-ctx] about JWT generation.

Called on each request.

Default implementation parses [JSON Web Token (JWT)][link-jwt] in `Authorization`
header and sets payload to `securityContext` if it's verified. More
information on how to generate these tokens is [here][ref-sec-ctx].

You can return object with `securityContext: userContextObj` field inside the middleware
if you want to customize [`SECURITY_CONTEXT`][ref-schema-cube-ref-ctx-sec-ctx].

Also, in JS config you can set it directly in request object.
You can return an object with the `securityContext` field if you want to
customize [`SECURITY_CONTEXT`][ref-schema-cube-ref-ctx-sec-ctx].

You can use empty `check_auth` function to disable built-in security or
raise an exception to fail the authentication check.
Expand All @@ -1106,8 +1102,8 @@ def check_auth(ctx: dict, token: str) -> None:

if token == 'my_secret_token':
return {
"securityContext": {
"user_id": 42
'securityContext': {
'user_id': 42
}
}

Expand All @@ -1118,7 +1114,11 @@ def check_auth(ctx: dict, token: str) -> None:
module.exports = {
checkAuth: ({ securityContext }, token) => {
if (token === 'my_secret_token') {
return;
return {
securityContext: {
user_id: 42
}
}
}

throw new Error('Access denied');
Expand Down

0 comments on commit 2eb0531

Please sign in to comment.