No auth data in the request after exchange the Discord code
👋 I'm fowling the built in Oauth2 route documentation but, every time that I fire a request after authenticate I have a
null
value in the request.auth
on the backend side.
Here is my frontend code for exchange the Discord code
and here is the Precondition
I'm using on the bot/backend side:
PS: The Discord code
was success exchange and I received the LoginData
back in the front end.31 Replies
You need to set
cookies: 'include'
in your frontend options. No idea if axios even supports that. Truth be told personally I recommend just using browser fetch. There is no reason to use XHR (what Axios wraps) in the current day and age unless you are uploading a file and you want to give an accurate progress to the user because XHR has event listeners.Looks like it might be withCredentials https://stackoverflow.com/a/43178070
Stack Overflow
Make Axios send cookies in its requests automatically
I am sending requests from the client to my Express.js server using Axios.
I set a cookie on the client and I want to read that cookie from all Axios requests without adding them manually to requ...
I tried the
withCredentials
using axios
but that did not work. I will give it a try using fetch
I changed it to fetch
but still getting the same problem
I also just tried what the skyra
is doing but I still don't see any cookie in my browser.
frontend
Frontend URL: http://127.0.0.1:3000
apiFetch
Discord code exchange request
A Request after the token exchange
Backend/bot
Bot URL: http://127.0.0.1:4000
.env
Authenticated precondition route
Guilds route
The backend response is including the access_token
in the header response: im on pc now so I can check more thoroughly
what are you (sapphire) client options looking like Daniel?
Specifically
.api
(hide the secret values by just putting the env var names or ''
or something)Thanks for looking into that @Favna but to be honest I don't think the problem is in the bot side, but here is my config anyway:
SapphireClient
.env
do you see the MORREA_AUTH token in your cookies? similar to this.
And what browser do you use? I know for Skyra there at least used to be a problem with Firefox. I think Firefox resolved it (it was definitely on their side) but I'm not too sure.
Also I think you need set
domainOverwrite
on the bot config
api.auth.domainOverwrite
to envParseString('OAUTH_DOMAIN_OVERWRITE')
and in dev set it to 127.0.0.1
No and that is "the problem" the front end is not "saving" the cookie, but it's receiving that information from the backend:
MORREA_AUTH=nFgNDjJ......==; Max-Age=604800; Domain=.0.1; Path=/; HttpOnly
Let me try the domainOverwrite
lets see by default what we do is
this.request.headers.host
should be 127.0.0.1:3000
after that...
right
so yeah that's definitely it
we pass it into the psl
library
and read domain
property
but domain
is 0.1
which you see in your backend as well (we return it as .${pslParsedInfo.domain}
)I've been meaning to make @sapphire/psl for a long time because that lib is abandoned <_<
I see!
I guess when I do I should make a simple
kind of check
So in theory that only happens because I'm using
127.0.0.1
, right?yes
Gotcha!
sadly however if you'd use
localhost
the cookie wouldnt be saved either because httponly cookies only work in a secure context or on that ip address
it's part of the httponly cookies specNice catch! I will try the
domainOverwrite
and also create a fake domain in my /etc/hosts
for production for @Skyra we set it to
OAUTH_DOMAIN_OVERWRITE=.skyra.pw
btw, the domain for @Skyra is https://skyra.pwSkyra
Skyra Dashboard
Skyra is a multipurpose Discord bot designed to handle most tasks, helping users manage their servers easily.
Cool! I will test it and let you know. Thanks for the help. I really appreciate that
Just wondering if we should have this information on the documentation website. WDYT?
adding this, waiting for it to compile now
You fast, even not give me time to do that LOL
tbf I was gonna write a message asking if you could maybe do it then I was like "ah hell it's probably faster if I do it" seeing as I'd otherwise have to explain about the submodules the website has and whatnot
Np at all. I really appreciate the job you guys are doing on the framework. Congrats!
for the record with that fake domain in your hosts file, it's pretty straightforward and should work in most cases I think but if you want to check how the domain will resolve beforehand just keep in mind we use the
psl
library.
Just tested and
domainOverwrite
works like a charm I see the cookie
on the front end now!
Thanks for the help, I really appreciate that. Enjoy your weekend!Why are you using psl and not tldts
1. Why are you using you when you have just as much responsibility so the proper address would be we
2. This is not a development channel. Please use the proper channel so these conversations do not get lost in the aether. I will answer this here once but I expect you to continue this conversation in #plugins-development
3. Well primarily because I didn't know it existed. That said, the tarball is also bloated because he published all the source .ts and the .tsbuildinfo files as well. The project is also very much showing it being outdated in that it still uses tsling and mocha.
About the last part, ehh, as long as it stays up to date with tlds, its fine
#plugins-development
fair enough about the other 2 points