Albert
Loading...
Searching...
No Matches
oauth.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Manuel Schneider
2// SPDX-License-Identifier: MIT
3
4#pragma once
5#include <QDateTime>
6#include <QObject>
7#include <QString>
8#include <albert/export.h>
9#include <memory>
10class QUrl;
11
12namespace albert
13{
14
23class ALBERT_EXPORT OAuth2 : public QObject
24{
25 Q_OBJECT
26public:
27
32
37
42
47
51 const QString &clientId() const;
52
56 void setClientId(const QString &id);
57
61 const QString &clientSecret() const;
62
66 void setClientSecret(const QString &secret);
67
71 const QString &scope() const;
72
76 void setScope(const QString &scope);
77
81 const QString &authUrl() const;
82
86 void setAuthUrl(const QString &url);
87
91 const QString &redirectUri() const;
92
96 void setRedirectUri(const QString &uri);
97
101 bool isPkceEnabled() const;
102
106 void setPkceEnabled(bool enabled);
107
111 const QString &tokenUrl() const;
112
116 void setTokenUrl(const QString &url);
117
121 const QString &accessToken() const;
122
126 const QString &refreshToken() const;
127
131 const QDateTime &tokenExpiration() const;
132
136 void setTokens(const QString &access_token,
137 const QString &refresh_token = {},
138 const QDateTime &expiration = {});
139
143 const QString &error() const;
144
145 enum class State {
146 NotAuthorized,
147 Awaiting,
148 Granted
149 };
150
154 State state() const;
155
159 void handleCallback(const QUrl &callback);
160
161signals:
162
163 void clientIdChanged(const QString &);
164 void clientSecretChanged(const QString &);
165 void scopeChanged(const QString &);
166 void authUrlChanged(const QString &);
167 void redirectUriChanged(const QString &);
168 void tokenUrlChanged(const QString &);
171
172private:
173
174 class Private;
175 std::unique_ptr<Private> d;
176
177};
178
179}
Provides OAuth2 authentication with support for the Authorization Code Flow with PKCE and refresh tok...
Definition oauth.h:24
OAuth2()
Constructs an OAuth2.
const QString & clientId() const
Returns the client identifier.
bool isPkceEnabled() const
Returns true if PKCE is enabled, false otherwise.
void setAuthUrl(const QString &url)
Sets the authorization URL to url.
State state() const
Returns the state of the authorization flow.
void clientIdChanged(const QString &)
Emitted when the client ID changes.
void setTokens(const QString &access_token, const QString &refresh_token={}, const QDateTime &expiration={})
Sets the access token, refresh token and expiration date.
void authUrlChanged(const QString &)
Emitted when the authorization URL changes.
const QString & refreshToken() const
Returns the access token.
void setPkceEnabled(bool enabled)
Sets whether PKCE is enabled or not.
void tokenUrlChanged(const QString &)
Emitted when the token URL changes.
void stateChanged(State)
Emitted when the state changes.
void clientSecretChanged(const QString &)
Emitted when the client secret changes.
void redirectUriChanged(const QString &)
Emitted when the redirect URI changes.
const QString & redirectUri() const
Returns the redirect URI.
void setRedirectUri(const QString &uri)
Sets the redirect URI to uri.
const QString & error() const
Returns the error message if any.
void setClientId(const QString &id)
Sets the client identifier to id.
void handleCallback(const QUrl &callback)
Handles the redirect callback URL from the OAuth2 provider.
const QString & tokenUrl() const
Returns the token URL.
const QString & authUrl() const
Returns the authorization URL.
void requestAccess()
Requests access, i.e.
void setClientSecret(const QString &secret)
Sets the client secret to secret.
void scopeChanged(const QString &)
Emitted when the scope changes.
const QDateTime & tokenExpiration() const
Returns the access token.
~OAuth2()
Destruct the OAuth2.
const QString & clientSecret() const
Returns the client secret.
const QString & accessToken() const
Returns the access token.
void updateTokens()
Updates the access token.
const QString & scope() const
Returns the OAuth scope to request permissions for.
void setScope(const QString &scope)
Sets the OAuth scope to request permissions for to scope.
State
Definition oauth.h:145
void setTokenUrl(const QString &url)
Sets the token URL to url.
void tokensChanged()
Emitted when the access token, refresh token or expiration date changes.
Definition app.h:56