Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token authentication fails with @directus/sdk (auth.static method only) #12644

Closed
Toilal opened this issue Apr 8, 2022 · 6 comments
Closed

Comments

@Toilal
Copy link
Contributor

Toilal commented Apr 8, 2022

Describe the Bug

I just upgrade to lastest directus server and @directus/sdk library, but token authentication fails to authenticate properly when using auth.static(token) method.

To Reproduce

Configure a token on a user, and run this script.

const sdk = new Directus('http://localhost:8080')
await sdk.auth.static('token')
await sdk.activity.readByQuery({
      limit: 1,
      sort: ['-timestamp'],
      filter: { _and: filters },
      fields: ['action', 'collection', 'timestamp', 'user.first_name', 'user.last_name'],
      meta: 'total_count'
    })

Errors Shown

You don't have permission to access this.

What version of Directus are you using?

v9.8.0

What version of Node.js are you using?

v16.14.2

What database are you using?

PostgreSQL 13

What browser are you using?

Chrome

How are you deploying Directus?

Docker

@Toilal
Copy link
Contributor Author

Toilal commented Apr 8, 2022

It seems the proper way to authenticate with token is through constructor, auth.static method doesn't work properly. Is it expected, maybe it should be removed ?

// This work using options from constructor
sdk = new Directus(config.url, {
  auth: {
    staticToken: config.token
  }
})

@Toilal Toilal changed the title Token authentication fails with @directus/sdk Token authentication fails with @directus/sdk (auth.static method only) Apr 8, 2022
@azrikahar
Copy link
Contributor

Is it expected, maybe it should be removed ?

Granted I haven't look into this yet, but I'm pretty sure it's not expected. Could be linked to #12399.

Out of curiosity and this question may end up not being relevant at all, are you running the script server side or client side?

@Toilal
Copy link
Contributor Author

Toilal commented Apr 8, 2022

I'm running this in NodeJS v16.

@azrikahar
Copy link
Contributor

I tested this locally but it seems to work (without using constructor etc):

Code_4DTdse7yWO.mp4

Are you able to reproduce this reliably even with a fresh Directus instance? or is this only happening to your specific instance?

@azrikahar
Copy link
Contributor

Oh and would you mind sharing the filter you are using? It'd also be helpful if you can try running it without the filter!

There is a possibility that it is related to a recent filter issue since I can't seem to reproduce it, but my test is without the filter in your code 🤔

@rijkvanzanten
Copy link
Member

I'm seeing the same behavior as @azrikahar on my end, so I'll close this for now. Happy to keep discussing/debugging tho!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants