KiCad PCB EDA Suite
Loading...
Searching...
No Matches
oauth_loopback_server.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 <wx/event.h>
23#include <wx/socket.h>
24#include <wx/string.h>
25#include <wx/timer.h>
26
27#include <memory>
28#include <optional>
29
30#include <kicommon.h>
31
32
33wxDECLARE_EXPORTED_EVENT( KICOMMON_API, EVT_OAUTH_LOOPBACK_RESULT, wxCommandEvent );
34
35
37{
38 wxString code;
39 wxString state;
40 wxString error;
42};
43
44
45class KICOMMON_API OAUTH_LOOPBACK_SERVER : public wxEvtHandler
46{
47public:
48 OAUTH_LOOPBACK_SERVER( wxEvtHandler* aOwner, const wxString& aCallbackPath,
49 const wxString& aExpectedState );
50 ~OAUTH_LOOPBACK_SERVER() override;
51
52 bool Start();
53 unsigned short GetPort() const { return m_port; }
54 wxString GetRedirectUri() const;
55
56 static bool ParseAuthorizationResponse( const wxString& aRequestLine,
57 const wxString& aExpectedPath,
58 const wxString& aExpectedState,
60 wxString& aError );
61
62private:
63 void OnSocketEvent( wxSocketEvent& aEvent );
64 void OnTimeout( wxTimerEvent& aEvent );
65 void HandleClient( wxSocketBase* aClient );
66 void SendHttpResponse( wxSocketBase* aClient, bool aSuccess );
67 void Finish( bool aSuccess );
68 void Shutdown();
69
70 wxEvtHandler* m_owner;
73 std::unique_ptr<wxSocketServer> m_server;
74 wxTimer m_timeout;
75 unsigned short m_port;
76 bool m_done;
77 std::optional<OAUTH_AUTHORIZATION_RESPONSE> m_response;
78};
unsigned short GetPort() const
OAUTH_LOOPBACK_SERVER(wxEvtHandler *aOwner, const wxString &aCallbackPath, const wxString &aExpectedState)
std::optional< OAUTH_AUTHORIZATION_RESPONSE > m_response
std::unique_ptr< wxSocketServer > m_server
#define KICOMMON_API
Definition kicommon.h:28
wxDECLARE_EXPORTED_EVENT(KICOMMON_API, EVT_OAUTH_LOOPBACK_RESULT, wxCommandEvent)