Skip to content

Commit

Permalink
UI: Invalidate OAuth tokens when disconnecting accoun account
Browse files Browse the repository at this point in the history
  • Loading branch information
derrod committed Jun 24, 2023
1 parent 2b1aa58 commit 20f7f2f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions UI/auth-restream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ using namespace json11;

#define RESTREAM_AUTH_URL OAUTH_BASE_URL "v1/restream/redirect"
#define RESTREAM_TOKEN_URL OAUTH_BASE_URL "v1/restream/token"
#define RESTREAM_REVOKE_URL "https://api.restream.io/oauth/revoke"
#define RESTREAM_STREAMKEY_URL "https://api.restream.io/v2/user/streamKey"
#define RESTREAM_SCOPE_VERSION 1

Expand Down Expand Up @@ -129,6 +130,12 @@ bool RestreamAuth::LoadInternal()
return OAuthStreamKey::LoadInternal();
}

void RestreamAuth::DeleteInternal()
{
InvalidateToken(RESTREAM_REVOKE_URL, "");
OAuthStreamKey::DeleteInternal();
}

void RestreamAuth::LoadUI()
{
if (uiLoaded)
Expand Down
1 change: 1 addition & 0 deletions UI/auth-restream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class RestreamAuth : public OAuthStreamKey {

virtual void SaveInternal() override;
virtual bool LoadInternal() override;
virtual void DeleteInternal() override;

bool GetChannelInfo();

Expand Down
10 changes: 10 additions & 0 deletions UI/auth-twitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ using namespace json11;

#define TWITCH_AUTH_URL OAUTH_BASE_URL "v1/twitch/redirect"
#define TWITCH_TOKEN_URL OAUTH_BASE_URL "v1/twitch/token"
#define TWITCH_REOKVE_URL "https://id.twitch.tv/oauth2/revoke"

#define TWITCH_SCOPE_VERSION 1

Expand Down Expand Up @@ -499,6 +500,15 @@ std::shared_ptr<Auth> TwitchAuth::Login(QWidget *parent, const std::string &)
return nullptr;
}

void TwitchAuth::DeleteInternal()
{
std::string client_id = TWITCH_CLIENTID;
deobfuscate_str(&client_id[0], TWITCH_HASH);

InvalidateToken(TWITCH_REOKVE_URL, client_id);
OAuthStreamKey::DeleteInternal();
}

static std::shared_ptr<Auth> CreateTwitchAuth()
{
return std::make_shared<TwitchAuth>(twitchDef);
Expand Down
1 change: 1 addition & 0 deletions UI/auth-twitch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class TwitchAuth : public OAuthStreamKey {

virtual void SaveInternal() override;
virtual bool LoadInternal() override;
virtual void DeleteInternal() override;

bool MakeApiRequest(const char *path, json11::Json &json_out);
bool GetChannelInfo();
Expand Down
7 changes: 7 additions & 0 deletions UI/auth-youtube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ using namespace json11;
/* ------------------------------------------------------------------------- */
#define YOUTUBE_AUTH_URL "https://accounts.google.com/o/oauth2/v2/auth"
#define YOUTUBE_TOKEN_URL "https://www.googleapis.com/oauth2/v4/token"
#define YOUTUBE_REVOKE_URL "https://oauth2.googleapis.com/revoke"
#define YOUTUBE_SCOPE_VERSION 1
#define YOUTUBE_API_STATE_LENGTH 32
#define SECTION_NAME "YouTube"
Expand Down Expand Up @@ -188,6 +189,12 @@ bool YoutubeAuth::LoadInternal()
return implicit ? !token.empty() : !refresh_token.empty();
}

void YoutubeAuth::DeleteInternal()
{
InvalidateToken(YOUTUBE_REVOKE_URL);
OAuthStreamKey::DeleteInternal();
}

#ifdef BROWSER_AVAILABLE
static const char *ytchat_script = "\
const obsCSS = document.createElement('style');\
Expand Down
1 change: 1 addition & 0 deletions UI/auth-youtube.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class YoutubeAuth : public OAuthStreamKey {
virtual bool RetryLogin() override;
virtual void SaveInternal() override;
virtual bool LoadInternal() override;
virtual void DeleteInternal() override;
virtual void LoadUI() override;

QString GenerateState();
Expand Down

0 comments on commit 20f7f2f

Please sign in to comment.