我正在尝试使用GraphQL (以前称为PostGraphQL)来设置一个PostGraphile服务器,但不能使行权限正常工作,这意味着我一直得到被拒绝权限的消息,尽管它应该能工作。下面是我的模式:
create function app.current_user() returns app.profile as $$
select *
from app.profile
where id = current_setting('jwt.claims.person_id')::integer
$$ language sql stable;
comment on function app.current_user() is 'Gets the person who was identified by our JWT.';
grant select (name,about,created_at,updated_at) on table app.profile to app_user;
grant update (name,about) on table app.profile to app_user;
alter table app.profile enable row level security;
create policy select_profile on app.profile for select to app_user
using (id = current_setting('jwt.claims.person_id')::integer);
create policy update_profile on app.profile for update to app_user
using (id = current_setting('jwt.claims.person_id')::integer);就我在调试输出中所能看到的情况而言,一切都正常工作。我可以对JWT令牌进行身份验证,得到一个JWT令牌,当JWT令牌无效时,它会发出一个正确的错误消息,所以没有任何错误消息。
我做错了什么,或者如何更密切地调试正在发生的事情?
我用的是PostGraphile v4和PostgreSQL 10.4
发布于 2018-07-09 12:54:51
我自己发现了问题。事实证明,即使您没有选择id,但只在WHERE部分使用它,也必须对id授予权限。
因此,在上面的示例中,将其修改为:
将表app.profile上的选择(id、name、about、created_at、updated_at)授予app_user;
那就应该管用了。
https://stackoverflow.com/questions/51236075
复制相似问题