summaryrefslogtreecommitdiff
path: root/indra/newview/llappviewer.cpp
diff options
context:
space:
mode:
authorErik Kundiman <erik@megapahit.org>2025-07-27 22:38:14 +0800
committerErik Kundiman <erik@megapahit.org>2025-07-27 22:45:06 +0800
commitec86ee28171428824cde4afe88d1165e80633233 (patch)
treefbd1e52a6d005a53b53e116eea51c48f3b283ac0 /indra/newview/llappviewer.cpp
parent01dfd0f960b1cd500fbbe9b544a7c22cd0ab548a (diff)
Connect to Discord now through privacy tab
Now the access token is saved the way passwords are saved, but without a username, so we can have some persistence without having to implement an OAuth2 backend server cause we would have to store those tokens there anyway still and that would even require more disclosure that the user token gets saved on a server, and it's just simpler to not go that way. Discord Social SDK doesn't have to have a helper for sending code to a custom server anyway, that we would have to have some asynchronous HTTP requestor ready. Show location check button gets enabled only when Discord integration is enabled, though it's not functioning yet.
Diffstat (limited to 'indra/newview/llappviewer.cpp')
-rw-r--r--indra/newview/llappviewer.cpp72
1 files changed, 50 insertions, 22 deletions
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 17f8c3e367..030c778990 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -5922,34 +5922,62 @@ void LLAppViewer::metricsSend(bool enable_reporting)
void LLAppViewer::initDiscordSocial()
{
- gDiscordClient = std::make_shared<discordpp::Client>();
- gDiscordClient->SetStatusChangedCallback([](discordpp::Client::Status status, discordpp::Client::Error, int32_t) {
- if (status == discordpp::Client::Status::Ready) {
- discordpp::Activity activity;
- activity.SetType(discordpp::ActivityTypes::Playing);
- gDiscordClient->UpdateRichPresence(activity, [](discordpp::ClientResult) {});
- }
+ gDiscordClient = std::make_shared<discordpp::Client>();
+ gDiscordClient->SetStatusChangedCallback([](discordpp::Client::Status status, discordpp::Client::Error, int32_t) {
+ if (status == discordpp::Client::Status::Ready)
+ {
+ discordpp::Activity activity;
+ activity.SetType(discordpp::ActivityTypes::Playing);
+ gDiscordClient->UpdateRichPresence(activity, [](discordpp::ClientResult) {});
+ }
+ });
+ if (gSavedSettings.getBOOL("EnableDiscord"))
+ {
+ gDiscordClient->UpdateToken(discordpp::AuthorizationTokenType::Bearer, gSecAPIHandler->loadCredential("Discord")->getAuthenticator()["token"].asString(), [](discordpp::ClientResult result) {
+ if (result.Successful())
+ gDiscordClient->Connect();
});
+ }
}
-void LLAppViewer::handleDiscordSocial()
+void LLAppViewer::handleDiscordSocial(bool enable)
{
static const uint64_t APPLICATION_ID = 1393451183741599796;
- discordpp::AuthorizationArgs args{};
- args.SetClientId(APPLICATION_ID);
- args.SetScopes(discordpp::Client::GetDefaultPresenceScopes());
- auto codeVerifier = gDiscordClient->CreateAuthorizationCodeVerifier();
- args.SetCodeChallenge(codeVerifier.Challenge());
- gDiscordClient->Authorize(args, [codeVerifier](auto result, auto code, auto redirectUri) {
- if (result.Successful()) {
- gDiscordClient->GetToken(APPLICATION_ID, code, codeVerifier.Verifier(), redirectUri, [](discordpp::ClientResult result, std::string accessToken, std::string, discordpp::AuthorizationTokenType, int32_t, std::string) {
- gDiscordClient->UpdateToken(discordpp::AuthorizationTokenType::Bearer, accessToken, [](discordpp::ClientResult result) {
- if (result.Successful())
- gDiscordClient->Connect();
+ if (enable)
+ {
+ discordpp::AuthorizationArgs args{};
+ args.SetClientId(APPLICATION_ID);
+ args.SetScopes(discordpp::Client::GetDefaultPresenceScopes());
+ auto codeVerifier = gDiscordClient->CreateAuthorizationCodeVerifier();
+ args.SetCodeChallenge(codeVerifier.Challenge());
+ gDiscordClient->Authorize(args, [codeVerifier](auto result, auto code, auto redirectUri) {
+ if (result.Successful())
+ {
+ gDiscordClient->GetToken(APPLICATION_ID, code, codeVerifier.Verifier(), redirectUri, [](discordpp::ClientResult result, std::string accessToken, std::string, discordpp::AuthorizationTokenType, int32_t, std::string) {
+ gDiscordClient->UpdateToken(discordpp::AuthorizationTokenType::Bearer, accessToken, [](discordpp::ClientResult result) {
+ if (result.Successful())
+ gDiscordClient->Connect();
});
- });
- }
- });
+ LLSD authenticator = LLSD::emptyMap();
+ authenticator["token"] = accessToken;
+ gSecAPIHandler->saveCredential(gSecAPIHandler->createCredential("Discord", LLSD::emptyMap(), authenticator), true);
+ });
+ }
+ else
+ {
+ gSavedSettings.setBOOL("EnableDiscord", false);
+ }
+ });
+ }
+ else
+ {
+ gDiscordClient->RevokeToken(APPLICATION_ID, gSecAPIHandler->loadCredential("Discord")->getAuthenticator()["token"].asString(), [](discordpp::ClientResult result) {
+ if (result.Successful())
+ gDiscordClient->Disconnect();
+ auto cred = new LLCredential("Discord");
+ gSecAPIHandler->deleteCredential(cred);
+ });
+ }
}
#endif