π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ
π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
so there is no need, my bad
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
O right, im caching the guilds
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
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
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
and the user table should contain the token and the refresh token?
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
so i should only send a JWT token containing my database userid?
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
for username, emain, avatar, guilds and similar stuff
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
Is it a good idea?
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
Is something like this possibile?
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
The token i need to save is the discord user oauth2 token
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
If i create a JWT token with the discord token in it and my own database user Id?
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
Is it a good idea? could't it compromise security?
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
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
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
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
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
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
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
I just have issues with how to implement it
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
Yes it does
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
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
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
I can only return future or blocking
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
how?
53 replies
JCHJava Community | Help. Code. Learn.
Created by π“–π“Ύπ“»π”€π“²πŸ‘πŸŽ on 3/2/2025 in #java-help
Implement discord authentication
public CompletableFuture<Optional<DiscordAccessTokenResponse>> getAccessTokenFromCode(String code) {
String data = String.format("grant_type=authorization_code&code=%s&redirect_uri=%s", code, redirectUri);

return webClient.post()
.uri("/token")
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Authorization", createAuthHeaderString(clientId, clientSecret))
.bodyValue(data)
.retrieve()
.bodyToMono(DiscordAccessTokenResponse.class)
.map(Optional::of)
.onErrorReturn(Optional.empty())
.doOnError(throwable -> LOGGER.error(throwable.getMessage(), throwable))
.toFuture();
}
public CompletableFuture<Optional<DiscordAccessTokenResponse>> getAccessTokenFromCode(String code) {
String data = String.format("grant_type=authorization_code&code=%s&redirect_uri=%s", code, redirectUri);

return webClient.post()
.uri("/token")
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Authorization", createAuthHeaderString(clientId, clientSecret))
.bodyValue(data)
.retrieve()
.bodyToMono(DiscordAccessTokenResponse.class)
.map(Optional::of)
.onErrorReturn(Optional.empty())
.doOnError(throwable -> LOGGER.error(throwable.getMessage(), throwable))
.toFuture();
}
So i should do .toBlocking() here?
53 replies