Audacity 3.2.0
|
Service responsible for OAuth authentication against the audio.com service. More...
#include <OAuthService.h>
Public Types | |
using | AuthSuccessCallback = std::function< void(std::string_view)> |
using | AuthFailureCallback = std::function< void(unsigned, std::string_view)> |
Public Types inherited from Observer::Publisher< AuthStateChangedMessage > | |
using | message_type = AuthStateChangedMessage |
using | CallbackReturn = std::conditional_t< true, void, bool > |
using | Callback = std::function< CallbackReturn(const AuthStateChangedMessage &) > |
Type of functions that can be connected to the Publisher. More... | |
Public Member Functions | |
bool | HasAccessToken () const |
Indicates, that service has a valid access token, i. e. that the user is authorized. More... | |
bool | HasRefreshToken () const |
void | ValidateAuth (AuthSuccessCallback completedHandler, AudiocomTrace, bool silent) |
Attempt to authorize the user. More... | |
bool | HandleLinkURI (std::string_view uri, AudiocomTrace, AuthSuccessCallback completedHandler) |
Handle the OAuth callback. More... | |
void | UnlinkAccount (AudiocomTrace) |
Removes access and refresh token, notifies about the logout. More... | |
std::string | GetAccessToken () const |
Return the current access token, if any. More... | |
std::string | MakeAudioComAuthorizeURL (std::string_view userId, std::string_view redirectUrl) |
Creates a link to authorize audio.com using current auth token. More... | |
void | Authorize (std::string_view email, std::string_view password, AuthSuccessCallback successCallback, AuthFailureCallback failureCallback, AudiocomTrace trace) |
void | Register (std::string_view email, std::string_view password, AuthSuccessCallback successCallback, AuthFailureCallback failureCallback, AudiocomTrace trace) |
Register a new user with email and password . More... | |
Public Member Functions inherited from Observer::Publisher< AuthStateChangedMessage > | |
Publisher (ExceptionPolicy *pPolicy=nullptr, Alloc a={}) | |
Constructor supporting type-erased custom allocation/deletion. More... | |
Publisher (Publisher &&)=default | |
Publisher & | operator= (Publisher &&)=default |
Subscription | Subscribe (Callback callback) |
Connect a callback to the Publisher; later-connected are called earlier. More... | |
Subscription | Subscribe (Object &obj, Return(Object::*callback)(Args...)) |
Overload of Subscribe takes an object and pointer-to-member-function. More... | |
Static Public Member Functions | |
static std::string | MakeOAuthRequestURL (std::string_view authClientId) |
Creates a link to authorization request dialog. More... | |
Private Types | |
using | Clock = std::chrono::steady_clock |
Private Member Functions | |
void | AuthorisePassword (const ServiceConfig &config, std::string_view userName, std::string_view password, AudiocomTrace, std::function< void(std::string_view)> completedHandler) |
void | AuthoriseRefreshToken (const ServiceConfig &config, std::string_view refreshToken, AudiocomTrace, std::function< void(std::string_view)> completedHandler, bool silent) |
void | AuthoriseRefreshToken (const ServiceConfig &config, AudiocomTrace, std::function< void(std::string_view)> completedHandler, bool silent) |
void | AuthoriseCode (const ServiceConfig &config, std::string_view authorizationCode, bool useAudioComRedirectURI, AudiocomTrace, std::function< void(std::string_view)> completedHandler) |
void | DoAuthorise (const ServiceConfig &config, std::string_view payload, AudiocomTrace, std::function< void(std::string_view)> completedHandler, bool silent) |
void | ParseTokenResponse (std::string_view response, AuthSuccessCallback successCallback, AuthFailureCallback failureCallback, AudiocomTrace trace, bool silent) |
void | SafePublish (const AuthStateChangedMessage &message) |
Private Attributes | |
std::recursive_mutex | mMutex |
Clock::time_point | mTokenExpirationTime |
std::string | mAccessToken |
Additional Inherited Members | |
Static Public Attributes inherited from Observer::Publisher< AuthStateChangedMessage > | |
static constexpr bool | notifies_all |
Protected Member Functions inherited from Observer::Publisher< AuthStateChangedMessage > | |
CallbackReturn | Publish (const AuthStateChangedMessage &message) |
Send a message to connected callbacks. More... | |
Service responsible for OAuth authentication against the audio.com service.
Definition at line 41 of file OAuthService.h.
using audacity::cloud::audiocom::OAuthService::AuthFailureCallback = std::function<void(unsigned, std::string_view)> |
Definition at line 46 of file OAuthService.h.
using audacity::cloud::audiocom::OAuthService::AuthSuccessCallback = std::function<void(std::string_view)> |
Definition at line 45 of file OAuthService.h.
|
private |
Definition at line 142 of file OAuthService.h.
|
private |
Definition at line 294 of file OAuthService.cpp.
References DoAuthorise(), audacity::cloud::audiocom::ServiceConfig::GetOAuthRedirectURL(), and audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::WriteCommonFields().
Referenced by HandleLinkURI().
|
private |
Definition at line 230 of file OAuthService.cpp.
References DoAuthorise(), audacity::cloud::audiocom::anonymous_namespace{UserService.cpp}::userName, and audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::WriteCommonFields().
Referenced by HandleLinkURI().
|
private |
Definition at line 283 of file OAuthService.cpp.
References AuthoriseRefreshToken(), mMutex, Setting< T >::Read(), audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::refreshToken, and audacity::ToUTF8().
|
private |
Definition at line 259 of file OAuthService.cpp.
References DoAuthorise(), and audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::WriteCommonFields().
Referenced by AuthoriseRefreshToken(), HandleLinkURI(), and ValidateAuth().
void audacity::cloud::audiocom::OAuthService::Authorize | ( | std::string_view | email, |
std::string_view | password, | ||
AuthSuccessCallback | successCallback, | ||
AuthFailureCallback | failureCallback, | ||
AudiocomTrace | trace | ||
) |
Definition at line 376 of file OAuthService.cpp.
References audacity::network_manager::common_headers::Accept, audacity::network_manager::common_content_types::ApplicationJson, audacity::network_manager::common_headers::ContentType, audacity::network_manager::NetworkManager::doPost(), audacity::network_manager::NetworkManager::GetInstance(), audacity::cloud::audiocom::GetServiceConfig(), ParseTokenResponse(), SafePublish(), audacity::network_manager::Request::setHeader(), and audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::WriteCommonFields().
|
private |
Definition at line 476 of file OAuthService.cpp.
References audacity::network_manager::common_headers::Accept, audacity::network_manager::common_content_types::ApplicationJson, BasicUI::CallAfter(), audacity::network_manager::common_headers::ContentType, audacity::network_manager::NetworkManager::doPost(), audacity::cloud::audiocom::ServiceConfig::GetAPIUrl(), audacity::network_manager::NetworkManager::GetInstance(), audacity::cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler, ParseTokenResponse(), SafePublish(), audacity::network_manager::Request::setHeader(), and UnlinkAccount().
Referenced by AuthoriseCode(), AuthorisePassword(), and AuthoriseRefreshToken().
std::string audacity::cloud::audiocom::OAuthService::GetAccessToken | ( | ) | const |
Return the current access token, if any.
Definition at line 335 of file OAuthService.cpp.
References mAccessToken, mMutex, and mTokenExpirationTime.
Referenced by HasAccessToken(), MakeAudioComAuthorizeURL(), audacity::cloud::audiocom::sync::LocalProjectSnapshot::UpdateProjectSnapshot(), and ValidateAuth().
bool audacity::cloud::audiocom::OAuthService::HandleLinkURI | ( | std::string_view | uri, |
AudiocomTrace | trace, | ||
AuthSuccessCallback | completedHandler | ||
) |
Handle the OAuth callback.
Definition at line 126 of file OAuthService.cpp.
References AuthoriseCode(), AuthorisePassword(), AuthoriseRefreshToken(), audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::authorizationCodePrefix, audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::codePrefix, audacity::cloud::audiocom::GetServiceConfig(), IsPrefixed(), IsPrefixedInsensitive(), Tuple::detail::npos(), audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::passwordPrefix, audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::tokenPrefix, audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::uriPrefix, audacity::UrlDecode(), and audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::usernamePrefix.
Referenced by audacity::cloud::audiocom::LinkWithTokenDialog::OnContinue().
bool audacity::cloud::audiocom::OAuthService::HasAccessToken | ( | ) | const |
Indicates, that service has a valid access token, i. e. that the user is authorized.
Definition at line 324 of file OAuthService.cpp.
References GetAccessToken().
Referenced by audacity::cloud::audiocom::anonymous_namespace{CloudSyncService.cpp}::PerformProjectGetRequest(), and ValidateAuth().
bool audacity::cloud::audiocom::OAuthService::HasRefreshToken | ( | ) | const |
Indicates, that the service has a possibly valid refresh token, which can be used to authorize the user
Definition at line 329 of file OAuthService.cpp.
References mMutex, Setting< T >::Read(), and audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::refreshToken.
Referenced by ValidateAuth().
std::string audacity::cloud::audiocom::OAuthService::MakeAudioComAuthorizeURL | ( | std::string_view | userId, |
std::string_view | redirectUrl | ||
) |
Creates a link to authorize audio.com using current auth token.
Definition at line 358 of file OAuthService.cpp.
References audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::concat(), GetAccessToken(), audacity::cloud::audiocom::GetServiceConfig(), Tuple::detail::npos(), audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::tokenPrefix, audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::urlPrefix, audacity::cloud::audiocom::anonymous_namespace{UserService.cpp}::userId, and audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::userPrefix.
|
static |
Creates a link to authorization request dialog.
Definition at line 345 of file OAuthService.cpp.
References audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::authClientPrefix, audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::clientIdPrefix, audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::concat(), audacity::cloud::audiocom::GetServiceConfig(), and audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::responseTypePrefix.
Referenced by LoginDialog::ContinueAuthorize().
|
private |
Definition at line 516 of file OAuthService.cpp.
References BasicUI::CallAfter(), audacity::BasicSettings::Flush(), gPrefs, mAccessToken, mMutex, mTokenExpirationTime, audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::refreshToken, SafePublish(), and Setting< T >::Write().
Referenced by Authorize(), DoAuthorise(), and Register().
void audacity::cloud::audiocom::OAuthService::Register | ( | std::string_view | email, |
std::string_view | password, | ||
AuthSuccessCallback | successCallback, | ||
AuthFailureCallback | failureCallback, | ||
AudiocomTrace | trace | ||
) |
Register a new user with email
and password
.
Definition at line 426 of file OAuthService.cpp.
References audacity::network_manager::common_headers::Accept, audacity::network_manager::common_content_types::ApplicationJson, audacity::network_manager::common_headers::ContentType, audacity::network_manager::NetworkManager::doPost(), audacity::network_manager::NetworkManager::GetInstance(), audacity::cloud::audiocom::GetServiceConfig(), ParseTokenResponse(), SafePublish(), audacity::network_manager::Request::setHeader(), and audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::WriteClientFields().
|
private |
Definition at line 564 of file OAuthService.cpp.
References BasicUI::CallAfter(), and Observer::Publisher< AuthStateChangedMessage >::Publish().
Referenced by Authorize(), DoAuthorise(), ParseTokenResponse(), and Register().
void audacity::cloud::audiocom::OAuthService::UnlinkAccount | ( | AudiocomTrace | trace | ) |
Removes access and refresh token, notifies about the logout.
Definition at line 217 of file OAuthService.cpp.
References audacity::BasicSettings::Flush(), gPrefs, mAccessToken, mMutex, Observer::Publisher< AuthStateChangedMessage >::Publish(), audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::refreshToken, and Setting< T >::Write().
Referenced by DoAuthorise(), audacity::cloud::audiocom::sync::ProjectCloudUIExtension::OnCloudStatusChanged(), and audacity::cloud::audiocom::anonymous_namespace{OAuthService.cpp}::OAuthServiceSettingsResetHandler::OnSettingResetEnd().
void audacity::cloud::audiocom::OAuthService::ValidateAuth | ( | AuthSuccessCallback | completedHandler, |
AudiocomTrace | trace, | ||
bool | silent | ||
) |
Attempt to authorize the user.
Definition at line 111 of file OAuthService.cpp.
References AuthoriseRefreshToken(), GetAccessToken(), audacity::cloud::audiocom::GetServiceConfig(), HasAccessToken(), and HasRefreshToken().
Referenced by audacity::cloud::audiocom::UploadService::Upload().
|
private |
Definition at line 147 of file OAuthService.h.
Referenced by GetAccessToken(), ParseTokenResponse(), and UnlinkAccount().
|
mutableprivate |
Definition at line 144 of file OAuthService.h.
Referenced by AuthoriseRefreshToken(), GetAccessToken(), HasRefreshToken(), ParseTokenResponse(), and UnlinkAccount().
|
private |
Definition at line 146 of file OAuthService.h.
Referenced by GetAccessToken(), and ParseTokenResponse().