#✅ Public endpoint : authenticate with a static token

15 messages · Page 1 of 1 (latest)

charred solstice
#

Hi! I'm receiving events from an external platform loading one of my custom endpoints.
I cannot change the headers on that platform, so I would like to authenticate within my extension code as a specific user with a static token.
Usually I just use the _req.accountability with my ItemsService, but I could not find how to create an accountability object myself with a static token that I know.

Is that possible ?

Thanks for your help !

fallen hingeBOT
#

Thanks for posting! This is a community powered server, so you may or may not get an answer based on available help and expertise. To increase your chances of somebody being able to help you, please help us help you making sure you:

  • Adding an explanation of exactly what you're trying to achieve.
  • Adding any and all related code or previous attempts.
  • Describing the exact issue or error you are facing.
  • Posting any screenshots if applicable.
  • Reading through https://stackoverflow.com/help/how-to-ask.

When you're done with this thread, please close it. Thanks! ✨

(If you have a support agreement and need help, please contact the core team via email.)

next moss
#
    const { getAccountabilityForToken } = await dynamicImport("@directus/api/utils/get-accountability-for-token");
    const tokenAccountability = await getAccountabilityForToken("token");
    
    // or

    const { getAccountabilityForRole } = await dynamicImport("@directus/api/utils/get-accountability-for-role");
    const roleAccountability = await getAccountabilityForToken("role-id");
#

the implementation of "dynamicImport" is up to you though.

#

I`d use role instead of token, because token requires you to haven user created, role you just need the role itself

#

I use that for exposing my own apis

charred solstice
#

thanks for your help @next moss ! I've looked at the getAccountabilityForToken it seems to populate just the user and role with ids. Maybe I could just do that with the role I need 🤔

next moss
#

it's all Directus does 🤷‍♂️

#

nevermind, seems like it's mutating the defaultAccountability object too. I'd have to check what I did

#

doesn't seem like it does much though, default object is pretty empty

charred solstice
fallen hingeBOT
#

✅ Public endpoint : authenticate with a static token