diff options
| author | Osmium Sorcerer <os@sof.beauty> | 2026-03-22 18:55:26 +0000 |
|---|---|---|
| committer | Osmium Sorcerer <os@sof.beauty> | 2026-03-29 22:22:25 +0000 |
| commit | a124f46861d549ddc13485536962e34d80de939a (patch) | |
| tree | 3553849323aa70fef1e198f3476a2abcc7adfe39 /src/auth_flow.h | |
| parent | b1ad938c37f4e175e5509f727d1033b074b134d4 (diff) | |
Add authentication dialog
Introduce start_auth_flow, a function invoked by typing `/auth username`
in OOC. It sends an public-key authentication request to the server,
starting the entire flow.
The flow invoves two dialogs: to select the key, and to enter the
passphrase to unlock the key. For convenience, each successful unlock
also remembers the key for that username on the server, storing this
in `saved_auth.json` (I chose JSON because I wanted it to stay
human-editable; INI would be better, but it suffers from bad platform
quirks in Qt).
Diffstat (limited to 'src/auth_flow.h')
| -rw-r--r-- | src/auth_flow.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/auth_flow.h b/src/auth_flow.h new file mode 100644 index 0000000..942e1aa --- /dev/null +++ b/src/auth_flow.h @@ -0,0 +1,66 @@ +#pragma once + +#include <QString> + +#include "aoapplication.h" +#include "ext_packet.h" +#include "keyring.h" + +class KeySelectDialog : public QDialog +{ + Q_OBJECT + +public: + explicit KeySelectDialog(KeyringModel *model, QStringView username, QWidget *parent = nullptr); + +private: + KeyringModel *m_model; + +signals: + void key_selected(QByteArrayView key_id, QStringView key_name); +}; + +class KeyPassphraseDialog : public QDialog +{ + Q_OBJECT + +public: + explicit KeyPassphraseDialog(QStringView key_name, QWidget *parent = nullptr); + void display_error(ResponseResult error) const; + +private: + QLabel *m_err_lbl; + QLineEdit *m_pw_line; + +signals: + void passphrase_submitted(QByteArrayView passphrase); +}; + +// The only reason this inherits QObject is so I can call deleteLater() +// when the authentication finishes. Auth flow involves coordinating two +// asynchronous dialogs emitting signals, so I'd rather let Qt's event loop +// clean everything up to be safe. +class AuthFlow : public QObject +{ + Q_OBJECT + +public: + explicit AuthFlow(AOApplication *ao_app, const AuthChallenge &challenge, QWidget *parent = nullptr); + +private: + enum class FlowMode + { + Default, + Saved + }; + + FlowMode m_mode; + AOApplication *m_ao_app; + AuthChallenge m_challenge; + KeySelectDialog *m_key_dlg; + KeyPassphraseDialog *m_pwd_dlg; + + void on_key_selected(QByteArrayView key_id, QStringView key_name); +}; + +void start_auth_flow(AOApplication *ao_app, QString username); |
