Skip to content

Commit

Permalink
UI: Add OAuth token invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
derrod committed Jun 24, 2023
1 parent cbf8c5a commit 900566a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
46 changes: 46 additions & 0 deletions UI/auth-oauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,52 @@ try {
return false;
}

bool OAuth::InvalidateToken(const char *url, const std::string &client_id)
{
return InvalidateTokenInternal(url, client_id);
}

bool OAuth::InvalidateTokenInternal(const char *url,
const std::string &client_id)
try {
std::string output;
std::string error;
std::string desc;

if (token.empty() || TokenExpired()) {
return true;
}

std::string post_data = "client_id=";
post_data += client_id;
post_data += "&token=";
post_data += token;

bool success = false;

auto func = [&]() {
success = GetRemoteFile(url, output, error, nullptr,
"application/x-www-form-urlencoded", "",
post_data.c_str(),
std::vector<std::string>(), nullptr, 5,
false);
};

ExecThreadedWithoutBlocking(func, QTStr("Auth.Revoking.Title"),
QTStr("Auth.Revoking.Text").arg(service()));
if (!success)
throw ErrorInfo("Failed to revoke token", error);

/* We don't really care about the result here, just assume it either
* succeeded or didn't matter. */
return true;

} catch (ErrorInfo &info) {
blog(LOG_WARNING, "%s: %s: %s", __FUNCTION__, info.message.c_str(),
info.error.c_str());
return false;
}

void OAuthStreamKey::OnStreamConfig()
{
if (key_.empty())
Expand Down
4 changes: 4 additions & 0 deletions UI/auth-oauth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ class OAuth : public Auth {
const std::string &secret,
const std::string &redirect_uri, int scope_ver,
const std::string &auth_code, bool retry);
bool InvalidateToken(const char *url, const std::string &client_id);

private:
bool GetTokenInternal(const char *url, const std::string &client_id,
const std::string &secret,
const std::string &redirect_uri, int scope_ver,
const std::string &auth_code, bool retry);

bool InvalidateTokenInternal(const char *url,
const std::string &client_id);
};

class OAuthStreamKey : public OAuth {
Expand Down
2 changes: 2 additions & 0 deletions UI/data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ ExtraBrowsers.DockName="Dock Name"
# Auth
Auth.Authing.Title="Authenticating..."
Auth.Authing.Text="Authenticating with %1, please wait..."
Auth.Revoking.Title="Logging out..."
Auth.Revoking.Text="Logging out of %1, please wait..."
Auth.AuthFailure.Title="Authentication Failure"
Auth.AuthFailure.Text="Failed to authenticate with %1:\n\n%2: %3"
Auth.InvalidScope.Title="Authentication Required"
Expand Down

0 comments on commit 900566a

Please sign in to comment.