Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
Loading...
Searching...
No Matches
orbit::middleware::OAuth2 Class Reference

Authorization-code flow helper. More...

#include <OAuth2.hpp>

Collaboration diagram for orbit::middleware::OAuth2:

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_
 

Detailed Description

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.

Member Typedef Documentation

◆ Handler

using orbit::middleware::OAuth2::Handler = std::function<void(http::HttpRequest&, std::shared_ptr<http::ResponseWriter>)>

Constructor & Destructor Documentation

◆ OAuth2()

orbit::middleware::OAuth2::OAuth2 ( const OAuth2Config &  config)

Member Function Documentation

◆ callback_handler()

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

◆ config()

const OAuth2Config & orbit::middleware::OAuth2::config ( ) const
inline

◆ github()

static OAuth2 orbit::middleware::OAuth2::github ( const std::string &  client_id,
const std::string &  client_secret,
const std::string &  redirect_uri 
)
static

◆ google()

static OAuth2 orbit::middleware::OAuth2::google ( const std::string &  client_id,
const std::string &  client_secret,
const std::string &  redirect_uri 
)
static

◆ login_handler()

Handler orbit::middleware::OAuth2::login_handler ( ) const

Member Data Documentation

◆ config_

OAuth2Config orbit::middleware::OAuth2::config_
private

The documentation for this class was generated from the following file: