pow icon indicating copy to clipboard operation
pow copied to clipboard

API auth token null

Open michelson opened this issue 3 years ago • 5 comments

Hi, I've followed the example on the Pow guides for API auth, it's working but the responses on registrations an sessions urls are giving an empty access token, like {"data":{"access_token":null,"renewal_token":null}} I guess it has something to do with the CredentialsCache or the PersistentSessionCache but I don't know really how to debug this.

using {:pow, "~> 1.0.21"} and phoenix {:phoenix, "~> 1.5.7"}

michelson avatar Dec 28 '20 04:12 michelson

@danschultzer I am also seeing this same issue when I try to test the api endpoionts.

when I try to run the first curl request

 curl -X POST -d "user[email][email protected]&user[password]=secret1234&user[password_confirmation]=secret1234" http://localhost:4000/api/v1/registration

the result I get is:

{"data":{"access_token":null,"renewal_token":null}}                                                                                                                                  

any advice on to proceed in debugging this?

I have not made any other modifications other than using the API auth guide in the docs.

ajstrand avatar Jan 08 '21 02:01 ajstrand

Sorry for the late reply!

There was a significant change in the API guide a while a ago with https://github.com/danschultzer/pow/pull/454 where the naming was changed for the conn.private keys from auth_token to access_token and renew_token to renewal_token. Could this be the reason it doesn't work?

I would run IO.inspect(conn.private) to debug this. If there is no token keys set at all, then I imagine it's because the API plug isn't running and you should verify that that plug MyAppWeb.APIAuthPlug, otp_app: :my_app is in the right place in the router/endpoint (and you are not calling plug Pow.Plug.Session subsequently).

danschultzer avatar Jan 31 '21 05:01 danschultzer

@danschultzer that's certainly possible that what you're describing could be the issue. I was on deadline of sorts(take-home project for an interview, so I switched to a different auth solution(phx.gen.auth).

I can spin up an example app using Pow this weekend though and see if what you suggested would fix the issue. Thanks for responding.

ajstrand avatar Feb 04 '21 06:02 ajstrand

Yeah, this sounds like a frustrating issue. I would be happy to see if you can replicate this issue. I've opened #597 to ensure that an error is raised if the keys are not set.

danschultzer avatar Feb 06 '21 17:02 danschultzer

Hi, @danschultzer, it seems this issue is still happening. I've debugged a bit and the Api plug is never called as you mentioned. also, in the docs is stated that we have to remove the plug Pow.Plug.Session, otp_app: :myapp from the endpoint, but when I remove that line I get another error:

** (Pow.Config.ConfigError) Pow configuration not found in connection. Please use a Pow plug that puts the Pow configuration in the plug connection. code: conn = pos

I'm using the latest pow, ~> 1.0.26 and the latest tutorial code, still no luck

michelson avatar Feb 16 '22 12:02 michelson