Conversation
|
I was having the same issue, but ended up just adding the functions into my own project directly since it looks like this project isn't being maintained. If it is, it would be great if this PR could be merged. One suggestion: In my project, I actually updated Something like this: -- CREATE OR REPLACE FUNCTION tests.authenticate_as (identifier text)
++ CREATE OR REPLACE FUNCTION tests.authenticate_as (identifier text, aal text)
RETURNS void
AS $$
DECLARE
user_data json;
original_auth_data text;
BEGIN
-- store the request.jwt.claims in a variable in case we need it
original_auth_data := current_setting('request.jwt.claims', true);
user_data := tests.get_supabase_user(identifier);
if user_data is null OR user_data ->> 'id' IS NULL then
RAISE EXCEPTION 'User with identifier % not found', identifier;
end if;
++ IF aal NOT IN ('aal1', 'aal2') THEN
++ RAISE EXCEPTION 'Invalid value for aal: %', aal;
++ END IF;
perform set_config('role', 'authenticated', true);
perform set_config('request.jwt.claims', json_build_object(
'sub', user_data ->> 'id',
'email', user_data ->> 'email',
'phone', user_data ->> 'phone',
'user_metadata', user_data -> 'raw_user_meta_data',
'app_metadata', user_data -> 'raw_app_meta_data',
-- 'aal','aal1',
++ 'aal', aal,
'amr', json_build_array(json_build_object('method', 'password', 'timestamp', extract(epoch from now())::integer))
)::text, true);
EXCEPTION
-- revert back to original auth data
WHEN OTHERS THEN
set local role authenticated;
set local "request.jwt.claims" to original_auth_data;
RAISE;
END
$$ LANGUAGE plpgsql;And then in tests: SELECT tests.authenticate_as('test_owner', 'aal2'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add missing JWT info for MFA