Audacity 3.2.0
|
Service responsible for OAuth authentication against the audio.com service. More...
#include <OAuthService.h>
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 (std::function< void(std::string_view)> completedHandler) |
Attempt to authorize the user. More... | |
void | HandleLinkURI (std::string_view uri, std::function< void(std::string_view)> completedHandler) |
Handle the OAuth callback. More... | |
void | UnlinkAccount () |
Removes access and refresh token, notifies about the logout. More... | |
std::string | GetAccessToken () const |
Return the current access token, if any. 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... | |
Private Types | |
using | Clock = std::chrono::steady_clock |
Private Member Functions | |
void | AuthorisePassword (const ServiceConfig &config, std::string_view userName, std::string_view password, std::function< void(std::string_view)> completedHandler) |
void | AuthoriseRefreshToken (const ServiceConfig &config, std::string_view refreshToken, std::function< void(std::string_view)> completedHandler) |
void | AuthoriseRefreshToken (const ServiceConfig &config, std::function< void(std::string_view)> completedHandler) |
void | AuthoriseCode (const ServiceConfig &config, std::string_view authorizationCode, std::function< void(std::string_view)> completedHandler) |
void | DoAuthorise (const ServiceConfig &config, std::string_view payload, std::function< void(std::string_view)> completedHandler) |
void | SafePublish (const AuthStateChangedMessage &message) |
Private Attributes | |
std::recursive_mutex | mMutex |
Clock::time_point | mTokenExpirationTime |
std::string | mAccessToken |
Additional Inherited Members | |
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... | |
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 36 of file OAuthService.h.
|
private |
Definition at line 102 of file OAuthService.h.
|
private |
Definition at line 247 of file OAuthService.cpp.
References DoAuthorise(), cloud::audiocom::ServiceConfig::GetOAuthRedirectURL(), and cloud::audiocom::anonymous_namespace{OAuthService.cpp}::WriteCommonFields().
Referenced by HandleLinkURI().
|
private |
Definition at line 183 of file OAuthService.cpp.
References DoAuthorise(), cloud::audiocom::anonymous_namespace{UserService.cpp}::userName, and cloud::audiocom::anonymous_namespace{OAuthService.cpp}::WriteCommonFields().
Referenced by HandleLinkURI().
|
private |
Definition at line 236 of file OAuthService.cpp.
References AuthoriseRefreshToken(), mMutex, Setting< T >::Read(), cloud::audiocom::anonymous_namespace{OAuthService.cpp}::refreshToken, and audacity::ToUTF8().
|
private |
Definition at line 212 of file OAuthService.cpp.
References DoAuthorise(), and cloud::audiocom::anonymous_namespace{OAuthService.cpp}::WriteCommonFields().
Referenced by AuthoriseRefreshToken(), HandleLinkURI(), and ValidateAuth().
|
private |
Definition at line 298 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::BasicSettings::Flush(), cloud::audiocom::ServiceConfig::GetAPIUrl(), anonymous_namespace{FrameStatistics.cpp}::GetInstance(), gPrefs, cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler, mAccessToken, mMutex, mTokenExpirationTime, cloud::audiocom::anonymous_namespace{OAuthService.cpp}::refreshToken, SafePublish(), audacity::network_manager::Request::setHeader(), UnlinkAccount(), and Setting< T >::Write().
Referenced by AuthoriseCode(), AuthorisePassword(), and AuthoriseRefreshToken().
std::string cloud::audiocom::OAuthService::GetAccessToken | ( | ) | const |
Return the current access token, if any.
Definition at line 288 of file OAuthService.cpp.
References mAccessToken, mMutex, and mTokenExpirationTime.
Referenced by HasAccessToken(), and ValidateAuth().
void cloud::audiocom::OAuthService::HandleLinkURI | ( | std::string_view | uri, |
std::function< void(std::string_view)> | completedHandler | ||
) |
Handle the OAuth callback.
Definition at line 98 of file OAuthService.cpp.
References AuthoriseCode(), AuthorisePassword(), AuthoriseRefreshToken(), cloud::audiocom::anonymous_namespace{OAuthService.cpp}::authorizationCodePrefix, cloud::audiocom::GetServiceConfig(), cloud::audiocom::anonymous_namespace{OAuthService.cpp}::IsPrefixed(), Tuple::detail::npos(), cloud::audiocom::anonymous_namespace{OAuthService.cpp}::passwordPrefix, cloud::audiocom::anonymous_namespace{OAuthService.cpp}::tokenPrefix, cloud::audiocom::anonymous_namespace{OAuthService.cpp}::uriPrefix, audacity::UrlDecode(), and cloud::audiocom::anonymous_namespace{OAuthService.cpp}::usernamePrefix.
Referenced by cloud::audiocom::LinkAccountDialog::OnContinue().
bool cloud::audiocom::OAuthService::HasAccessToken | ( | ) | const |
Indicates, that service has a valid access token, i. e. that the user is authorized.
Definition at line 277 of file OAuthService.cpp.
References GetAccessToken().
Referenced by ValidateAuth().
bool 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 282 of file OAuthService.cpp.
References mMutex, Setting< T >::Read(), and cloud::audiocom::anonymous_namespace{OAuthService.cpp}::refreshToken.
Referenced by ValidateAuth().
|
private |
Definition at line 378 of file OAuthService.cpp.
References BasicUI::CallAfter(), and Observer::Publisher< AuthStateChangedMessage >::Publish().
Referenced by DoAuthorise().
void cloud::audiocom::OAuthService::UnlinkAccount | ( | ) |
Removes access and refresh token, notifies about the logout.
Definition at line 170 of file OAuthService.cpp.
References audacity::BasicSettings::Flush(), gPrefs, mAccessToken, mMutex, Observer::Publisher< AuthStateChangedMessage >::Publish(), cloud::audiocom::anonymous_namespace{OAuthService.cpp}::refreshToken, and Setting< T >::Write().
Referenced by DoAuthorise().
void cloud::audiocom::OAuthService::ValidateAuth | ( | std::function< void(std::string_view)> | completedHandler | ) |
Attempt to authorize the user.
Definition at line 85 of file OAuthService.cpp.
References AuthoriseRefreshToken(), GetAccessToken(), cloud::audiocom::GetServiceConfig(), HasAccessToken(), and HasRefreshToken().
Referenced by cloud::audiocom::UploadService::Upload().
|
private |
Definition at line 107 of file OAuthService.h.
Referenced by DoAuthorise(), GetAccessToken(), and UnlinkAccount().
|
mutableprivate |
Definition at line 104 of file OAuthService.h.
Referenced by AuthoriseRefreshToken(), DoAuthorise(), GetAccessToken(), HasRefreshToken(), and UnlinkAccount().
|
private |
Definition at line 106 of file OAuthService.h.
Referenced by DoAuthorise(), and GetAccessToken().