WebAccountManagerAuthenticator.h (1546B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include <atomic> 5 #include "Public/winget/Authentication.h" 6 #include <winrt/Windows.Security.Authentication.Web.Core.h> 7 #include <winrt/Windows.Security.Credentials.h> 8 9 namespace AppInstaller::Authentication 10 { 11 struct WebAccountManagerAuthenticator : public IAuthenticationProvider 12 { 13 WebAccountManagerAuthenticator(AuthenticationInfo info, AuthenticationArguments args); 14 15 AuthenticationResult AuthenticateForToken(); 16 17 private: 18 AuthenticationInfo m_authInfo; 19 AuthenticationArguments m_authArgs; 20 winrt::Windows::Security::Credentials::WebAccountProvider m_webAccountProvider = nullptr; 21 winrt::Windows::Security::Credentials::WebAccount m_authenticatedAccount = nullptr; 22 std::mutex m_authLock; 23 24 winrt::Windows::Security::Credentials::WebAccount FindWebAccount(std::string_view accountName); 25 winrt::Windows::Security::Authentication::Web::Core::WebTokenRequest CreateTokenRequest(bool forceInteractive); 26 AuthenticationResult GetToken(winrt::Windows::Security::Credentials::WebAccount webAccount, bool forceInteractive = false); 27 AuthenticationResult GetTokenSilent(winrt::Windows::Security::Credentials::WebAccount webAccount); 28 AuthenticationResult HandleGetTokenResult(winrt::Windows::Security::Authentication::Web::Core::WebTokenRequestResult requestResult); 29 30 bool IsMicrosoftEntraIdAuthenticationType(); 31 }; 32 }