Implement discord authentication
Hi, im tring to add login with discord in my nextjs and springboot application but i can't find what should be the best way to implement it, i reimplemented in a lot of different ways but nothing seems the right way to do it.
35 Replies
β
This post has been reserved for your question.
Hey @ππΎπ»ππ²ππ! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
what do you mean? show us examples
this servers bot uses discord4j https://github.com/Java-Discord/JavaBot
Im creating a discord bot with a web interaface, and i need to make the user login on the website using the discord oauth2 service, but i don't know how to do it without any security vunerability
This is the current code for the auth endpoint
security is hard, why do you think this is insecure>
I searched online i saw people setting up websecurity stuff, and im not understanding how to do it
not relatable to the question but why do you use async with request mapping
Because i have the getAccessTokenFrom code method wich returns a completablefuture
yeah i dont think that works the way you think lol, try without it as well
So i should do .toBlocking() here?
no never, if you are need blocking you are doing it incorrectly
just return Optional<DiscordAccessTokenResponse>
how?
I can only return future or blocking
ahh you are using webclient, do you intend your endpoint to be reactive?
then return Mono else just use RestClient i think for blocking apis
I need to make the user login and retrive the access token from discord api so i can make requests to discord getting the user information like username and server
have you tried this does it work?
Yes it does
I just have issues with how to implement it
The current one works but it sucks, it's just a mess to work with and i need to make contiuous database requests and api calls to discord api
because im not storing the user info after retriving them from discord, but i need to retrive them from the discord api and then get my own user data and send them when the user endpoint is called
But thats not the issue, i don't know how to setup the websecurity part, and i don't know what should i save in the user cookie
wouldnt you save tokens returned by discord?
Is it a good idea? could't it compromise security?
you can always hash them
i mean someone is able to access your cookies your users have bigger problemes
If i create a JWT token with the discord token in it and my own database user Id?
what no, you need the token for api requests
oh lmao i thought you meant storing them in a db
even for storing in database hashing makes no sense
this isnt a password
The token i need to save is the discord user oauth2 token
Is something like this possibile?
yeah its possible
Is it a good idea?
so your application will make discord api call only for username/email?
for username, emain, avatar, guilds and similar stuff
then store token on your server
not in cookies
so i should only send a JWT token containing my database userid?
and the user table should contain the token and the refresh token?
yep
encrypted of course
should i cache it in redis? because for things like retriving the guilds i don't need any data from my database but only the discord token
thats up to you
if you like redis then thats fine
things like retriving the guilds i don't need any data from my database but only the discord tokenwouldnt you run into rate limits?
O right, im caching the guilds
so there is no need, my bad
π€
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.