You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to be able to work with postgres' SCRAM-SHA-256 password hashes, we also need the PBKDF2 key derivation function. Luckily there is `a PL/pgSQL implementation on stackoverflow <https://stackoverflow.com/a/72805848>`_:
@@ -120,7 +120,7 @@ In order to be able to work with postgres' SCRAM-SHA-256 password hashes, we als
120
120
Analogous to :ref:`sql_user_management` creates the function :code:`basic_auth.user_role`, we create a helper function to check the user's password, here with another name and signature (since we want the username, not an email address).
121
121
But contrary to :ref:`sql_user_management`, this function does not use a dedicated :code:`users` table with passwords, but instead utilizes the built-in table `pg_catalog.pg_authid <https://www.postgresql.org/docs/current/catalog-pg-authid.html>`_:
122
122
123
-
.. code-block:: plpgsql
123
+
.. code-block:: postgres
124
124
125
125
CREATE FUNCTION basic_auth.check_user_pass(username text, password text) RETURNS name
126
126
LANGUAGE sql
@@ -160,7 +160,7 @@ Logins
160
160
As described in :ref:`client_auth`, we'll create a JWT token inside our login function. Note that you'll need to adjust the secret key which is hard-coded in this example to a secure (at least thirty-two character) secret of your choosing.
Copy file name to clipboardExpand all lines: docs/how-tos/sql-user-management.rst
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ First we'll need a table to keep track of our users:
28
28
29
29
We would like the role to be a foreign key to actual database roles, however PostgreSQL does not support these constraints against the :code:`pg_roles` table. We'll use a trigger to manually enforce it.
30
30
31
-
.. code-block:: plpgsql
31
+
.. code-block:: postgres
32
32
33
33
create or replace function
34
34
basic_auth.check_role_exists() returns trigger as $$
@@ -50,7 +50,7 @@ We would like the role to be a foreign key to actual database roles, however Pos
50
50
51
51
Next we'll use the pgcrypto extension and a trigger to keep passwords safe in the :code:`users` table.
52
52
53
-
.. code-block:: plpgsql
53
+
.. code-block:: postgres
54
54
55
55
create extension if not exists pgcrypto;
56
56
@@ -72,7 +72,7 @@ Next we'll use the pgcrypto extension and a trigger to keep passwords safe in th
72
72
73
73
With the table in place we can make a helper to check a password against the encrypted column. It returns the database role for a user if the email and password are correct.
74
74
75
-
.. code-block:: plpgsql
75
+
.. code-block:: postgres
76
76
77
77
create or replace function
78
78
basic_auth.user_role(email text, pass text) returns name
Copy file name to clipboardExpand all lines: docs/references/api/openapi.rst
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ PostgREST automatically serves a full `OpenAPI <https://www.openapis.org/>`_ des
11
11
12
12
For extra customization, the OpenAPI output contains a "description" field for every `SQL comment <https://www.postgresql.org/docs/current/sql-comment.html>`_ on any database object. For instance,
13
13
14
-
.. code-block:: sql
14
+
.. code-block:: postgres
15
15
16
16
COMMENT ON SCHEMA mammals IS
17
17
'A warm-blooded vertebrate animal of a class that is distinguished by the secretion of milk by females for the nourishment of the young';
@@ -26,7 +26,7 @@ These unsavory comments will appear in the generated JSON as the fields, ``info.
26
26
27
27
Also if you wish to generate a ``summary`` field you can do it by having a multiple line comment, the ``summary`` will be the first line and the ``description`` the lines that follow it:
28
28
29
-
.. code-block:: plpgsql
29
+
.. code-block:: postgres
30
30
31
31
COMMENT ON TABLE entities IS
32
32
$$Entities summary
@@ -37,7 +37,7 @@ Also if you wish to generate a ``summary`` field you can do it by having a multi
37
37
38
38
Similarly, you can override the API title by commenting the schema.
Copy file name to clipboardExpand all lines: docs/references/api/tables_views.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,7 +88,7 @@ any :code:`ANY` comparison matches any value in the list
88
88
89
89
For more complicated filters you will have to create a new view in the database, or use a stored procedure. For instance, here's a view to show "today's stories" including possibly older pinned stories:
Copy file name to clipboardExpand all lines: docs/references/errors.rst
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -339,7 +339,7 @@ RAISE errors with HTTP Status Codes
339
339
340
340
Custom status codes can be done by raising SQL exceptions inside :ref:`functions <s_procs>`. For instance, here's a saucy function that always responds with an error:
341
341
342
-
.. code-block:: postgresql
342
+
.. code-block:: postgres
343
343
344
344
CREATE OR REPLACE FUNCTION just_fail() RETURNS void
345
345
LANGUAGE plpgsql
@@ -366,7 +366,7 @@ One way to customize the HTTP status code is by raising particular exceptions ac
366
366
367
367
For even greater control of the HTTP status code, raise an exception of the ``PTxyz`` type. For instance to respond with HTTP 402, raise ``PT402``:
368
368
369
-
.. code-block:: sql
369
+
.. code-block:: postgres
370
370
371
371
RAISE sqlstate 'PT402' using
372
372
message = 'Payment Required',
@@ -394,7 +394,7 @@ Add HTTP Headers with RAISE
394
394
395
395
For full control over headers and status you can raise a ``PGRST`` SQLSTATE error. You can achieve this by adding the ``code``, ``message``, ``detail`` and ``hint`` in the PostgreSQL error message field as a JSON object. Here, the ``details`` and ``hint`` are optional. Similarly, the ``status`` and ``headers`` must be added to the SQL error detail field as a JSON object. For instance:
396
396
397
-
.. code-block:: sql
397
+
.. code-block:: postgres
398
398
399
399
RAISE sqlstate 'PGRST' USING
400
400
message = '{"code":"123","message":"Payment Required","details":"Quota exceeded","hint":"Upgrade your plan"}',
@@ -418,7 +418,7 @@ Returns:
418
418
419
419
For non standard HTTP status, you can optionally add ``status_text`` to describe the status code. For status code ``419`` the detail field may look like this:
0 commit comments