customClaims provide option for default value
I am using customClaims where for some cases this session variable might be null.
when I have permissions setup with {"org_id":{"_eq":"x-hasura-default-org"}}, when x-hasura-default-org is null, I will get invalid input syntax for type uuid: \"null\" error
[[auth.session.accessToken.customClaims]]
key = 'default-org'
value = 'defaultOrg'
Ask
as suggested in this hasura issue, provide option to set default value for customClaims e.g.
[[auth.session.accessToken.customClaims]]
key = 'default-org'
value = 'defaultOrg'
defalt = '00000000-0000-0000-0000-000000000000'
https://github.com/hasura/graphql-engine/issues/5134
This makes total sense to me, is this something you may be able to contribute?
Sure, can you point me which files I should explore
Unfortunately because not all endpoints are migrated from node to go we have to fix this in two places so while the change is probably not too hard (famous last words), it probably requires a lot of changes.
For node, the magic happens here: https://github.com/nhost/hasura-auth/blob/main/src/utils/jwt/custom-claims.ts#L91
For gi it is this file: https://github.com/nhost/hasura-auth/blob/main/go/controller/custom_claims.go
I think the first thing we need to consider is how to configure this. My main concern is that the way that the env var AUTH_JWT_CUSTOM_CLAIMS works now it might be too difficult to change so it might be easier to just add a second one AUTH_JWT_CUSTOM_CLAIMS_DEFAULTS that follows the same format but provides default values.
For isntance:
AUTH_JWT_CUSTOM_CLAIMS={"organisation-id":"profile.organisation[].id", "project-ids":"profile.contributesTo[].project.id"}
# no need to match all the keys
AUTH_JWT_CUSTOM_CLAIMS_DEFAULTS={"organisation-id":"00000000-0000-0000-0000-000000000000"}
any feedback on using jsonPath struct to hold the default value?
What is the defaultValue type you recommend ? *string or *any ?
type jsonPath struct {
path string
jpath *jsonpath.JSONPath
defaultValue *any
}
that's probably a fine place. Regarding type, I think any is better in case there is need to support other types (no need for a pointer as any can be a pointer already)
please review go implementation https://github.com/nhost/hasura-auth/pull/614 will work on node side next
updated TS files to support default for Custom Claims
opened new PR with pnpm audit --fix applied.
https://github.com/nhost/hasura-auth/pull/616