From 1f12dedce6b0d3fe10e95c5ba91351d87d22f382 Mon Sep 17 00:00:00 2001 From: Joe Nelson Date: Fri, 2 Dec 2016 10:15:12 -0800 Subject: [PATCH] Include Ruslan's env_var helper function in note --- auth.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/auth.rst b/auth.rst index f94533646..2430a5009 100644 --- a/auth.rst +++ b/auth.rst @@ -103,6 +103,28 @@ This allows JWT generation services to include extra information and your databa -- an exception if the setting is not present. Default it to ''. ALTER DATABASE your_db_name SET request.claim.email TO ''; + If you are unable to issue an ALTER DATABASE statement (for instance on Amazon RDS), you can create a helper function to read environment variables and swallow exceptions. + + .. code:: plpgsql + + create function env_var(v text) returns text as $$ + declare + result text; + begin + begin + select current_setting(v) into result; + exception + when undefined_object then + return null; + end; + + return result; + end; + $$ stable language plpgsql; + + -- now you can call call for instance + -- SELECT env_var('request.claim.email') + Hybrid User-Group Roles ~~~~~~~~~~~~~~~~~~~~~~~