serpent
Just getting into multi-tenancy and the Ash support for it. My schema looks like:
Organisation (global, tenant entity)
Identity (global) —(has many)—> User (tenant)
User (tenant) —(has many)—> Project (tenant)
Token (global)
So if a User has a record, it means the Identity belongs to the same Organisation as the User record. Authentication is performed for Identity.
Is this reasonable so far?
Now I want to add the API key strategy. But the assumptions are based on a uni-tenant configuration, it seems, adding another strategy to what my schema calls Identity now. But I need the API keys to be associated to an organisation as well, so they need to work for User.
Can I just enable extensions: [AshAuthentication] for User? Of course I tried, but Ash complains:
** (Spark.Error.DslError) authentication -> tokens -> enabled?:
The `:api_key` authentication strategy requires tokens be enabled.
But “tokens” means JWT tokens, no?
What is the recommended approach here? Or is there a flaw in my foundation?
Thanks again to the Ash team for the amazing work! ![]()
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
Tokens are not necessarily JWTs. It is the token resource that we use to store api keys.
zachdaniel
Actually, let me double check myself on that front.
zachdaniel
Yeah, I’m just misremembering the implementation. We should not be requiring that. Fixed here: fix: don't require token resource for API keys · team-alembic/ash_authentication@b95b22e · GitHub
serpent
Ok, tried with latest version. Now it says for
User:So I added
(full user.ex)
leading to:
It seems, it does rely on “tokens” somehow…
zachdaniel
Looks like just another check I need to fix
zachdaniel
You can try
mainagain.serpent
Yay, was able to create a token!
Thank you, Zach!
Found a GraphQL error message that might deserve proper handling. Just FYI, optional cosmetics for now…
Just need to fix my scoping plug now, I guess…
zachdaniel
Hmm…that one is interesting. So the reason we did that is that externally the term for a tenant might be something other than “tenant”, so it would make sense to have you implement that yourself. There is a guide on doing that IIRC.
serpent
Ok, I introduced some denormalisation to avoid walking the tenant tables:
Organisation(global, tenant entity) —(has many)—>ApiKey(global)User(tenant) —(has many)—>ApiKey(global)I want to authenticate
User(tenant) viaApiKey(global):Useris only accessible via tenant. Tenant can be derived directly fromApiKey.AshAuthentication says:
Which is a valid complaint…
What’s a good way to set the tenant? Maybe I could sneak in another
before_actionto validate (or at least identify) the API key and fetchOrganisationviaApiKey, set the context, and let AshAuth validate it again. But that would be double work and I’m not sure it would even work, it seems, AshAuth (or tenant read actions in general) bails out before it even runs (which makes sense).Copying
AshAuthentication.Strategy.ApiKey.SignInPreparationand patching it to do that is not an option either, as AshAuth becomes mutinous unless exactly that preparation is present. And again, wouldn’t run anyway.Ideas welcome.
zachdaniel
Ah, interesting. I think what you can do is allow bypassing multi tenancy for that read action, since every api key will uniquely be uniquely identified.