KiCad PCB EDA Suite
Loading...
Searching...
No Matches
secure_token_store.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <memory>
23#include <optional>
24
25#include <kicommon.h>
26#include <wx/string.h>
27
28
30{
31 wxString access_token;
32 wxString refresh_token;
33 wxString id_token;
34 wxString token_type;
35 wxString scope;
36 long long expires_at = 0;
37
38 bool operator==( const OAUTH_TOKEN_SET& aOther ) const = default;
39};
40
41
43{
44public:
45 virtual ~OAUTH_SECRET_BACKEND() = default;
46
47 virtual bool StoreSecret( const wxString& aService, const wxString& aKey,
48 const wxString& aSecret ) = 0;
49 virtual bool GetSecret( const wxString& aService, const wxString& aKey,
50 wxString& aSecret ) const = 0;
51 virtual bool DeleteSecret( const wxString& aService, const wxString& aKey ) = 0;
52};
53
54
56{
57public:
58 bool StoreSecret( const wxString& aService, const wxString& aKey,
59 const wxString& aSecret ) override;
60 bool GetSecret( const wxString& aService, const wxString& aKey,
61 wxString& aSecret ) const override;
62 bool DeleteSecret( const wxString& aService, const wxString& aKey ) override;
63};
64
65
67{
68public:
69 explicit SECURE_TOKEN_STORE(
70 std::unique_ptr<OAUTH_SECRET_BACKEND> aBackend = std::make_unique<PLATFORM_SECRET_BACKEND>() );
71
72 bool StoreTokens( const wxString& aProviderId, const wxString& aAccountId,
73 const OAUTH_TOKEN_SET& aTokens );
74 std::optional<OAUTH_TOKEN_SET> LoadTokens( const wxString& aProviderId,
75 const wxString& aAccountId ) const;
76 bool DeleteTokens( const wxString& aProviderId, const wxString& aAccountId );
77
78 static wxString MakeServiceName( const wxString& aProviderId );
79
80private:
81 std::unique_ptr<OAUTH_SECRET_BACKEND> m_backend;
82};
virtual ~OAUTH_SECRET_BACKEND()=default
virtual bool GetSecret(const wxString &aService, const wxString &aKey, wxString &aSecret) const =0
virtual bool DeleteSecret(const wxString &aService, const wxString &aKey)=0
virtual bool StoreSecret(const wxString &aService, const wxString &aKey, const wxString &aSecret)=0
bool GetSecret(const wxString &aService, const wxString &aKey, wxString &aSecret) const override
bool StoreSecret(const wxString &aService, const wxString &aKey, const wxString &aSecret) override
bool DeleteSecret(const wxString &aService, const wxString &aKey) override
std::unique_ptr< OAUTH_SECRET_BACKEND > m_backend
bool DeleteTokens(const wxString &aProviderId, const wxString &aAccountId)
std::optional< OAUTH_TOKEN_SET > LoadTokens(const wxString &aProviderId, const wxString &aAccountId) const
static wxString MakeServiceName(const wxString &aProviderId)
SECURE_TOKEN_STORE(std::unique_ptr< OAUTH_SECRET_BACKEND > aBackend=std::make_unique< PLATFORM_SECRET_BACKEND >())
bool StoreTokens(const wxString &aProviderId, const wxString &aAccountId, const OAUTH_TOKEN_SET &aTokens)
#define KICOMMON_API
Definition kicommon.h:28
bool operator==(const OAUTH_TOKEN_SET &aOther) const =default