api.accessToken.setCustomClaim and api.idToken.setCustomClaim Start of namesapace string

,

Hi,
Why namespace in Actions must starts with https:// or http:// ?

This one works:

exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://test.api';
  if (event.authorization) {
    api.accessToken.setCustomClaim(`${namespace}/ip`, event.request.ip);
    api.accessToken.setCustomClaim(`${namespace}/hostname`, event.request.hostname);
    api.accessToken.setCustomClaim(`${namespace}/geoip`, event.request.geoip);
    api.idToken.setCustomClaim(`${namespace}/ip`, event.request.ip);
    api.idToken.setCustomClaim(`${namespace}/hostname`, event.request.hostname);
    api.idToken.setCustomClaim(`${namespace}/geoip`, event.request.geoip);
  }
};

but this one does not work:

exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'urn:test.api';
  if (event.authorization) {
    api.accessToken.setCustomClaim(`${namespace}/ip`, event.request.ip);
    api.accessToken.setCustomClaim(`${namespace}/hostname`, event.request.hostname);
    api.accessToken.setCustomClaim(`${namespace}/geoip`, event.request.geoip);
    api.idToken.setCustomClaim(`${namespace}/ip`, event.request.ip);
    api.idToken.setCustomClaim(`${namespace}/hostname`, event.request.hostname);
    api.idToken.setCustomClaim(`${namespace}/geoip`, event.request.geoip);
  }
};

Hi @Ronan ,

Welcome to the Auth0 Community!

Why namespace in Actions must starts with https:// or http:// ?

In this Auth0 doc, there is example of action code with the declaration of the namespace variable:

const namespace = "https://my-app.example.com";

It looks to me that’s how we should declare this variable.

Hope it helps!

Thank you for your answer but I already know this document. In this it is not written that http:// or https:// is a mandatory namespace. It is only a sample.
That’s why in my message I gave a working code with https:// and a not working code.
For example in the API audience I use some identifiers like “urn:api:identifier” because if an api is shared between multiple web sites it makes no sense to use an url.
My question is still WHY because nowhere I saw the mandatory word, but perhaps I’m wrong.
Ronan

Thank you for the reply. I believe this article provided more insights regarding your concern. Please let us know if any other queries.

1 Like