Yes, of course
Perhaps this is related:
https://github.com/directus/docs/issues/163
@benhaynes I've made my first custom endpoint and would like to authenticate the user in it, is there any example in the docs somewhere? 馃檹馃徏 th盲nk y枚眉!
Hmm, that would be a question for @rijkvanzanten
Passing that on to @bjgajjar
pass it around @bjgajjar 馃槀
@bjgajjar I'd be interested in this as well. Currently there seems to be no good option/example on how to limit access to custom endpoints? By default anyone (without authentication) can use all custom endpoints. We'd like to limit it to logged in users/access the user-object.
Any workaround for this?
Is there any way to check if the user is authenticated inside the handler?
I've dug a little bit into the Directus source code and prepared a basic example on how to authenticate a user on a custom endpoint with a static token.
The example is composed of a small mixin that retrieves the auth token from the request and then pass it to the Directus API, plus a sample custom endpoint implementing the mixin.
https://gist.github.com/apiraino/aa2a2302afa54b3e1c22b990acddc8cf
Pretty basic but it should give the idea.
Directus exposes its public APIs under \Directus\Services, there's a lot of interesting stuff there.
hth
Also, cross-referencing with the documentation is useful:
https://docs.directus.io/api/authentication.html
Most helpful comment
I've dug a little bit into the Directus source code and prepared a basic example on how to authenticate a user on a custom endpoint with a static token.
The example is composed of a small mixin that retrieves the auth token from the request and then pass it to the Directus API, plus a sample custom endpoint implementing the mixin.
https://gist.github.com/apiraino/aa2a2302afa54b3e1c22b990acddc8cf
Pretty basic but it should give the idea.
Directus exposes its public APIs under \Directus\Services, there's a lot of interesting stuff there.
hth