-
From the Tutorial part 1: "PostgREST allows us to specify a stored procedure to run during attempted authentication. The function can do whatever it likes, including raising an exception to terminate the request." Is this function not run when claim is rejected, and web_anon (PGRST_DB_ANON_ROLE) is reverted to? I was hoping that it would be run. I use asymmetric keys for jwt-secret and Azure AD to manage loging. I trust a decoded jwt claim from there (I can also do a check on tenant ID to be doubly sure they aren't able to manipulate the role coming from a different tenant for example). In this case, I just want to create a role of a previously unseen user, set the role and get on with the request. e.g. where CREATE OR REPLACE FUNCTION auth.pre_request()
RETURNS void AS $$
DECLARE
CLAIMED_USER text;
BEGIN
CLAIMED_USER := current_setting('request.jwt.claims')::json->>'role';
IF CURRENT_USER != CLAIMED_USER AND CLAIMED_USER LIKE '%@hellodnk8n.onmicrosoft.com' THEN
PERFORM auth.onboard_user(CLAIMED_USER);
END IF;
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION auth.onboard_user(role_name text)
RETURNS void AS $$
BEGIN
CREATE ROLE role_name;
SET LOCAL ROLE role_name;
END;
$$ LANGUAGE plpgsql; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Actually, thinking about this a bit more. I wouldn't want the condition |
Beta Was this translation helpful? Give feedback.
Actually, thinking about this a bit more. I wouldn't want the condition
IF CURRENT_USER != CLAIMED_USER AND CLAIMED_USER LIKE '%@hellodnk8n.onmicrosoft.com'
to be run at each and every request. I will see if I can split it out to an /rpc/ endpoint, which the frontend can run and redirect to where it was.