|
Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
|
Authorization-code flow helper. More...
#include <OAuth2.hpp>

Public Types | |
| using | Handler = std::function< void(http::HttpRequest &, std::shared_ptr< http::ResponseWriter >)> |
Public Member Functions | |
| OAuth2 (const OAuth2Config &config) | |
| Handler | login_handler () const |
| Handler | callback_handler (std::function< void(const nlohmann::json &user_info, http::HttpRequest &, std::shared_ptr< http::ResponseWriter >)> on_success, std::function< void(const std::string &error, http::HttpRequest &, std::shared_ptr< http::ResponseWriter >)> on_error) const |
| const OAuth2Config & | config () const |
Static Public Member Functions | |
| static OAuth2 | google (const std::string &client_id, const std::string &client_secret, const std::string &redirect_uri) |
| static OAuth2 | github (const std::string &client_id, const std::string &client_secret, const std::string &redirect_uri) |
Private Attributes | |
| OAuth2Config | config_ |
Authorization-code flow helper.
login_handler() redirects to the provider with a random state (and a PKCE challenge), remembered in short-lived HttpOnly cookies. callback_handler() rejects callbacks whose state does not match, which prevents login CSRF, then exchanges the code (with the PKCE verifier) and fetches the user info.
The handlers copy the configuration, so the OAuth2 object may be a temporary. Provider requests block the calling worker thread for at most request_timeout_seconds.
| using orbit::middleware::OAuth2::Handler = std::function<void(http::HttpRequest&, std::shared_ptr<http::ResponseWriter>)> |
| orbit::middleware::OAuth2::OAuth2 | ( | const OAuth2Config & | config | ) |
| Handler orbit::middleware::OAuth2::callback_handler | ( | std::function< void(const nlohmann::json &user_info, http::HttpRequest &, std::shared_ptr< http::ResponseWriter >)> | on_success, |
| std::function< void(const std::string &error, http::HttpRequest &, std::shared_ptr< http::ResponseWriter >)> | on_error | ||
| ) | const |
|
inline |
|
static |
|
static |
| Handler orbit::middleware::OAuth2::login_handler | ( | ) | const |
|
private |