mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-11-17 07:03:26 -06:00
Prepare built-in OAuth client for YouTube connections
This commit is contained in:
2
.github/workflows/build-project.yaml
vendored
2
.github/workflows/build-project.yaml
vendored
@@ -7,6 +7,8 @@ on:
|
||||
value: ${{ jobs.check-event.outputs.pluginName }}
|
||||
env:
|
||||
DEP_DIR: .deps/advss-build-dependencies-6
|
||||
ADVSS_YOUTUBE_CLIENT_ID: ${{ secrets.ADVSS_YOUTUBE_CLIENT_ID }}
|
||||
ADVSS_YOUTUBE_CLIENT_SECRET: ${{ secrets.ADVSS_YOUTUBE_CLIENT_SECRET }}
|
||||
jobs:
|
||||
check-event:
|
||||
name: Check GitHub Event Data 🔎
|
||||
|
||||
@@ -1988,7 +1988,10 @@ AdvSceneSwitcher.youtubeConnection.invalid="Invalid YouTube connection"
|
||||
AdvSceneSwitcher.youtubeConnection.name="Channel name:"
|
||||
AdvSceneSwitcher.youtubeConnection.clientId="Client ID:"
|
||||
AdvSceneSwitcher.youtubeConnection.clientSecret="Client secret:"
|
||||
AdvSceneSwitcher.youtubeConnection.useOwnClient="Use OAuth credentials of my own Google Cloud project"
|
||||
AdvSceneSwitcher.youtubeConnection.useOwnClient.tooltip="All users of the built-in client share its daily YouTube API quota.\nUse your own Google Cloud project if you run into quota limits, e.g. due to conditions checked for long periods of time."
|
||||
AdvSceneSwitcher.youtubeConnection.clientConfig.help="YouTube connections use the OAuth credentials of your own Google Cloud project:\n\n1. Create a project at console.cloud.google.com\n2. Enable the \"YouTube Data API v3\"\n3. Configure the OAuth consent screen with the audience \"External\"\n4. Set the publishing status to \"In production\", otherwise the connection expires after 7 days\n5. Create an OAuth client ID of the type \"Desktop app\"\n6. Enter the client ID and client secret here"
|
||||
AdvSceneSwitcher.youtubeConnection.setupGuide="<a href=\"https://github.com/WarmUpTill/SceneSwitcher/wiki/YouTube-connection-setup\">Setup guide and troubleshooting</a>"
|
||||
AdvSceneSwitcher.youtubeConnection.connect="Connect Account"
|
||||
AdvSceneSwitcher.youtubeConnection.connect.waiting="Waiting for approval in the browser ... (%1 s)"
|
||||
AdvSceneSwitcher.youtubeConnection.connect.success="Account is connected!"
|
||||
|
||||
@@ -64,6 +64,7 @@ target_sources(
|
||||
macro-action-youtube.hpp
|
||||
macro-condition-youtube.cpp
|
||||
macro-condition-youtube.hpp
|
||||
youtube-builtin-client.cpp
|
||||
youtube-connection.cpp
|
||||
youtube-connection.hpp
|
||||
youtube-helpers.cpp
|
||||
@@ -73,6 +74,20 @@ target_sources(
|
||||
youtube-tab.cpp
|
||||
youtube-tab.hpp)
|
||||
|
||||
# Without these the users have to provide the OAuth credentials of their own
|
||||
# Google Cloud project
|
||||
set(ADVSS_YOUTUBE_CLIENT_ID
|
||||
"$ENV{ADVSS_YOUTUBE_CLIENT_ID}"
|
||||
CACHE STRING "OAuth client ID of the built-in YouTube client")
|
||||
set(ADVSS_YOUTUBE_CLIENT_SECRET
|
||||
"$ENV{ADVSS_YOUTUBE_CLIENT_SECRET}"
|
||||
CACHE STRING "OAuth client secret of the built-in YouTube client")
|
||||
mark_as_advanced(ADVSS_YOUTUBE_CLIENT_ID ADVSS_YOUTUBE_CLIENT_SECRET)
|
||||
configure_file(youtube-client-config.hpp.in
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/youtube-client-config.hpp" @ONLY)
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
setup_advss_plugin(${PROJECT_NAME})
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE "${CPP_HTTPLIB_DIR}/"
|
||||
|
||||
16
plugins/youtube/youtube-builtin-client.cpp
Normal file
16
plugins/youtube/youtube-builtin-client.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "youtube-oauth.hpp"
|
||||
#include "youtube-client-config.hpp"
|
||||
|
||||
namespace advss {
|
||||
|
||||
std::optional<OAuthClientConfig> GetBuiltInClientConfig()
|
||||
{
|
||||
static const std::string clientId = ADVSS_YOUTUBE_CLIENT_ID;
|
||||
static const std::string clientSecret = ADVSS_YOUTUBE_CLIENT_SECRET;
|
||||
if (clientId.empty() || clientSecret.empty()) {
|
||||
return {};
|
||||
}
|
||||
return OAuthClientConfig{clientId, clientSecret};
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
4
plugins/youtube/youtube-client-config.hpp.in
Normal file
4
plugins/youtube/youtube-client-config.hpp.in
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#define ADVSS_YOUTUBE_CLIENT_ID "@ADVSS_YOUTUBE_CLIENT_ID@"
|
||||
#define ADVSS_YOUTUBE_CLIENT_SECRET "@ADVSS_YOUTUBE_CLIENT_SECRET@"
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "youtube-tab.hpp"
|
||||
|
||||
#include <help-icon.hpp>
|
||||
#include <layout-helpers.hpp>
|
||||
#include <log-helper.hpp>
|
||||
#include <macro-export-extensions.hpp>
|
||||
#include <obs-module-helper.hpp>
|
||||
@@ -444,6 +445,9 @@ YouTubeConnectionSettingsDialog::YouTubeConnectionSettingsDialog(
|
||||
"AdvSceneSwitcher.youtubeConnection.add",
|
||||
"AdvSceneSwitcher.youtubeConnection.nameNotAvailable", false,
|
||||
parent),
|
||||
_useOwnClient(new QCheckBox(obs_module_text(
|
||||
"AdvSceneSwitcher.youtubeConnection.useOwnClient"))),
|
||||
_layout(new QGridLayout()),
|
||||
_clientId(new QLineEdit(
|
||||
QString::fromStdString(settings._customClientId))),
|
||||
_clientSecret(new QLineEdit(
|
||||
@@ -459,7 +463,13 @@ YouTubeConnectionSettingsDialog::YouTubeConnectionSettingsDialog(
|
||||
_name->setReadOnly(true);
|
||||
_clientSecret->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
||||
_status->setWordWrap(true);
|
||||
_useOwnClient->setToolTip(obs_module_text(
|
||||
"AdvSceneSwitcher.youtubeConnection.useOwnClient.tooltip"));
|
||||
_useOwnClient->setChecked(!settings._customClientId.empty());
|
||||
_useOwnClient->setVisible(GetBuiltInClientConfig().has_value());
|
||||
|
||||
QWidget::connect(_useOwnClient, &QCheckBox::toggled, this,
|
||||
&YouTubeConnectionSettingsDialog::UseOwnClientChanged);
|
||||
QWidget::connect(_clientId, &QLineEdit::textEdited, this,
|
||||
&YouTubeConnectionSettingsDialog::ClientConfigChanged);
|
||||
QWidget::connect(_clientSecret, &QLineEdit::textEdited, this,
|
||||
@@ -471,15 +481,16 @@ YouTubeConnectionSettingsDialog::YouTubeConnectionSettingsDialog(
|
||||
QWidget::connect(&_countdownTimer, &QTimer::timeout, this,
|
||||
&YouTubeConnectionSettingsDialog::UpdateWaitingStatus);
|
||||
|
||||
auto grid = new QGridLayout();
|
||||
int row = 0;
|
||||
grid->addWidget(new QLabel(obs_module_text(
|
||||
"AdvSceneSwitcher.youtubeConnection.name")),
|
||||
row, 0);
|
||||
_layout->addWidget(new QLabel(obs_module_text(
|
||||
"AdvSceneSwitcher.youtubeConnection.name")),
|
||||
row, 0);
|
||||
auto nameLayout = new QHBoxLayout();
|
||||
nameLayout->addWidget(_name);
|
||||
nameLayout->addWidget(_nameHint);
|
||||
grid->addLayout(nameLayout, row, 1);
|
||||
_layout->addLayout(nameLayout, row, 1);
|
||||
++row;
|
||||
_layout->addWidget(_useOwnClient, row, 0, 1, 2);
|
||||
++row;
|
||||
auto clientIdLabelLayout = new QHBoxLayout();
|
||||
clientIdLabelLayout->addWidget(new QLabel(obs_module_text(
|
||||
@@ -487,20 +498,27 @@ YouTubeConnectionSettingsDialog::YouTubeConnectionSettingsDialog(
|
||||
clientIdLabelLayout->addWidget(new HelpIcon(obs_module_text(
|
||||
"AdvSceneSwitcher.youtubeConnection.clientConfig.help")));
|
||||
clientIdLabelLayout->addStretch();
|
||||
grid->addLayout(clientIdLabelLayout, row, 0);
|
||||
grid->addWidget(_clientId, row, 1);
|
||||
_layout->addLayout(clientIdLabelLayout, row, 0);
|
||||
_layout->addWidget(_clientId, row, 1);
|
||||
_clientIdRow = row;
|
||||
++row;
|
||||
grid->addWidget(
|
||||
_layout->addWidget(
|
||||
new QLabel(obs_module_text(
|
||||
"AdvSceneSwitcher.youtubeConnection.clientSecret")),
|
||||
row, 0);
|
||||
grid->addWidget(_clientSecret, row, 1);
|
||||
_layout->addWidget(_clientSecret, row, 1);
|
||||
_clientSecretRow = row;
|
||||
++row;
|
||||
grid->addWidget(_connect, row, 0);
|
||||
grid->addWidget(_status, row, 1);
|
||||
_layout->addWidget(_connect, row, 0);
|
||||
_layout->addWidget(_status, row, 1);
|
||||
|
||||
auto setupGuide = new QLabel(obs_module_text(
|
||||
"AdvSceneSwitcher.youtubeConnection.setupGuide"));
|
||||
setupGuide->setOpenExternalLinks(true);
|
||||
|
||||
auto layout = new QVBoxLayout();
|
||||
layout->addLayout(grid);
|
||||
layout->addLayout(_layout);
|
||||
layout->addWidget(setupGuide);
|
||||
layout->addWidget(_warnIfInvalid);
|
||||
layout->addWidget(_buttonbox);
|
||||
setLayout(layout);
|
||||
@@ -513,14 +531,38 @@ YouTubeConnectionSettingsDialog::YouTubeConnectionSettingsDialog(
|
||||
if (_name->text().isEmpty()) {
|
||||
HighlightWidget(_connect, Qt::green, QColor(0, 0, 0, 0), true);
|
||||
}
|
||||
|
||||
SetClientConfigVisibility();
|
||||
}
|
||||
|
||||
bool YouTubeConnectionSettingsDialog::UseOwnClient() const
|
||||
{
|
||||
return !GetBuiltInClientConfig() || _useOwnClient->isChecked();
|
||||
}
|
||||
|
||||
void YouTubeConnectionSettingsDialog::SetClientConfigVisibility()
|
||||
{
|
||||
const bool visible = UseOwnClient();
|
||||
SetGridLayoutRowVisible(_layout, _clientIdRow, visible);
|
||||
SetGridLayoutRowVisible(_layout, _clientSecretRow, visible);
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
void YouTubeConnectionSettingsDialog::UseOwnClientChanged()
|
||||
{
|
||||
SetClientConfigVisibility();
|
||||
ClientConfigChanged();
|
||||
}
|
||||
|
||||
void YouTubeConnectionSettingsDialog::ClientConfigChanged()
|
||||
{
|
||||
// An empty custom client ID selects the built-in client
|
||||
const bool useOwnClient = UseOwnClient();
|
||||
_currentConnection._customClientId =
|
||||
_clientId->text().trimmed().toStdString();
|
||||
useOwnClient ? _clientId->text().trimmed().toStdString() : "";
|
||||
_currentConnection._customClientSecret =
|
||||
_clientSecret->text().trimmed().toStdString();
|
||||
useOwnClient ? _clientSecret->text().trimmed().toStdString()
|
||||
: "";
|
||||
_currentConnection._refreshToken.clear();
|
||||
_currentConnection._accessToken.clear();
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <QCheckBox>
|
||||
#include <QGridLayout>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
|
||||
@@ -91,13 +92,20 @@ public:
|
||||
|
||||
private slots:
|
||||
void ClientConfigChanged();
|
||||
void UseOwnClientChanged();
|
||||
void Connect();
|
||||
void AuthFinished();
|
||||
void UpdateWaitingStatus();
|
||||
|
||||
private:
|
||||
void SetErrorStatus(const std::string &errorReason);
|
||||
bool UseOwnClient() const;
|
||||
void SetClientConfigVisibility();
|
||||
|
||||
QCheckBox *_useOwnClient;
|
||||
QGridLayout *_layout;
|
||||
int _clientIdRow = -1;
|
||||
int _clientSecretRow = -1;
|
||||
QLineEdit *_clientId;
|
||||
QLineEdit *_clientSecret;
|
||||
QPushButton *_connect;
|
||||
|
||||
@@ -13,11 +13,6 @@ static const char *authEndpoint =
|
||||
"https://accounts.google.com/o/oauth2/v2/auth";
|
||||
static const char *youtubeScope = "https://www.googleapis.com/auth/youtube";
|
||||
|
||||
std::optional<OAuthClientConfig> GetBuiltInClientConfig()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
static std::string generateRandomString(size_t length)
|
||||
{
|
||||
static const std::string chars =
|
||||
|
||||
Reference in New Issue
Block a user