ash json api

I added ash json api via mix igniter.install ash_json_api and updated resource via mix ash.patch.extend AshTableVue.GoldenDataset.Resources.Question json_api Then Added routes to domain. in my router.ex


pipeline :api do
plug :accepts, ["json"]
plug :load_from_bearer
plug :set_actor, :user
plug AshAuthentication.Strategy.ApiKey.Plug, resource: AshTableVue.Accounts.User
end

scope "/api/json" do
pipe_through [:api]

forward "/swaggerui", OpenApiSpex.Plug.SwaggerUI,
path: "/api/json/open_api",
default_model_expand_depth: 4

forward "/", AshTableVueWeb.AshJsonApiRouter
end


pipeline :api do
plug :accepts, ["json"]
plug :load_from_bearer
plug :set_actor, :user
plug AshAuthentication.Strategy.ApiKey.Plug, resource: AshTableVue.Accounts.User
end

scope "/api/json" do
pipe_through [:api]

forward "/swaggerui", OpenApiSpex.Plug.SwaggerUI,
path: "/api/json/open_api",
default_model_expand_depth: 4

forward "/", AshTableVueWeb.AshJsonApiRouter
end
Now, when i go to http://localhost:4000/api/json/swaggerui, it shows unauthorized! Why? I've logged in via /sign-in route already.
4 Replies
abeeshake456
abeeshake456OP5mo ago
as a workaround, I've commented out
plug AshAuthentication.Strategy.ApiKey.Plug, resource: AshTableVue.Accounts.User
plug AshAuthentication.Strategy.ApiKey.Plug, resource: AshTableVue.Accounts.User
sevenseacat
sevenseacat5mo ago
that seems a likely cause, if its running after your set_actor plug
abeeshake456
abeeshake456OP5mo ago
even if I re-order the plugs, and doing plug :set_actor, :user at the last. still does not work.
ZachDaniel
ZachDaniel5mo ago
Yeah it's the api key plug I believe we've fixed it with the newer installers for api keys But by default like that it prevents access if no api key is set You'd add required?: false to basically allow api key auth but not require it. As a plug option

Did you find this page helpful?