Wt: Wt::Auth::OAuthAuthorizationEndpointProcess Class Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | List of all members
Wt::Auth::OAuthAuthorizationEndpointProcess Class Reference

Allows clients to authorize users according to the OAuth 2.0 protocol. More...

`#include <Wt/Auth/OAuthAuthorizationEndpointProcess.h>`

Inheritance diagram for Wt::Auth::OAuthAuthorizationEndpointProcess:
[legend]

## Public Member Functions
| OAuthAuthorizationEndpointProcess (Login &login, AbstractUserDatabase &db)
| Constructor.
void | processEnvironment ()
| Processes the environment and authorizes the user when already logged in.
bool | validRequest () const
| Returns true if the request was a valid OAuth request with the correct parameters.
Signal< std::string > & | authorized ()
| This signal is emitted when the user has successfully logged in.
void | authorizeScope (const std::string &scope)
| Authorize the given scope and redirect the user.
void | setAuthCodeExpSecs (int seconds)
| Sets the amount of seconds after which generated authorization codes expire.
Public Member Functions inherited from Wt::WObject
void | addChild (std::unique_ptr< WObject > child)
| Add a child WObject whose lifetime is determined by this WObject.
template<typename Child >
Child * | addChild (std::unique_ptr< Child > child)
| Add a child WObject, returning a raw pointer.
std::unique_ptr< WObject > | removeChild (WObject *child)
| Remove a child WObject, so its lifetime is no longer determined by this WObject.
template<typename Child >
std::unique_ptr< Child > | removeChild (Child *child)
| Remove a child WObject, so its lifetime is no longer determined by this WObject.
virtual const std::string | id () const
| Returns the (unique) identifier for this object.
virtual void | setObjectName (const std::string &name)
| Sets an object name.
virtual std::string | objectName () const
| Returns the object name.
void | resetLearnedSlots ()
| Resets learned stateless slot implementations.
template<class T >
void | resetLearnedSlot (void(T::*method)())
| Resets a learned stateless slot implementation.
template<class T >
WStatelessSlot * | implementStateless (void(T::*method)())
| Declares a slot to be stateless and learn client-side behaviour on first invocation.
template<class T >
WStatelessSlot * | implementStateless (void(T::*method)(), void(T::*undoMethod)())
| Declares a slot to be stateless and learn client-side behaviour in advance.
void | isNotStateless ()
| Marks the current function as not stateless.
template<class T >
WStatelessSlot * | implementJavaScript (void(T::*method)(), const std::string &jsCode)
| Provides a JavaScript implementation for a method.
Public Member Functions inherited from Wt::Core::observable
| observable () noexcept
| Default constructor.
virtual | ~observable ()
| Destructor.
template<typename... Args, typename C >
auto | bindSafe (void(C::*method)(Args...)) noexcept
| Protects a method call against object destruction.
template<typename... Args, typename C >
auto | bindSafe (void(C::*method)(Args...) const) const noexcept
| Protects a const method call against object destruction.
template<typename Function >
auto | bindSafe (const Function &function) noexcept
| Protects a function against object destruction.

## Additional Inherited Members
Public Types inherited from Wt::WObject
typedef void(WObject::*) | Method()
| Typedef for a WObject method without arguments.
Static Public Member Functions inherited from Wt::WObject
Protected Member Functions inherited from Wt::WObject
virtual WStatelessSlot * | getStateless (Method method)
| On-demand stateless slot implementation.

## Detailed Description

Allows clients to authorize users according to the OAuth 2.0 protocol.

This class will process the environment and perform the authorization of the user if this is possible. If this is successful, an authorization code will be sent to the client.

The following URL parameters are expected: "client_id", which obviously has to contain a valid client ID. "redirect_uri", which has to be a valid redirect URI where the user will be redirected to when the authorization has been succesful. "scope", which has to be set to the scope of the requested information. "response_type", which has to be set to "code". If the "state" parameter has been included, it will be passed on as a paremeter to the redirect URI.

When the client ID and the redirect URI is valid but something else went wrong, an "error=invalid_request" will be sent to the client. If the user failed to log in correctly "error=login_required" will be sent. If everything went OK, the "code" parameter is included which can be used to obtain a token from a token endpoint.

See https://tools.ietf.org/rfc/rfc6749.txt for more information.

This class relies on a correct implementation of several function in the AbstractUserDatabase. Namely AbstractUserDatabase::idpClientFindWithId, AbstractUserDatabase::idpTokenAdd, and AbstractUserDatabase::idpClientRedirectUris.

Must be deployed with TLS.

Example:

process = std::make_unique<OAuthAuthorizationEndpointProcess>(
login,
database);
process->authorized().connect(
process.get(),
&OAuthAuthorizationEndpointProcess::authorizeScope);
process->processEnvironment();
if (process->validRequest()) {
root()->addWidget(std::move(authWidget));
} else
root()->addWidget(std::make_unique<Wt::WText>(Wt::utf8("The request was invalid."));
Wt::Auth::OAuthAuthorizationEndpointProcess::authorizeScope
void authorizeScope(const std::string &scope)
Authorize the given scope and redirect the user.
Wt::WString::utf8
WT_API WString utf8(const char *value)
Short hand for WString(const char * value, CharEncoding::UTF8)

See also
  OAuthTokenEndpoint
  AbstractUserDatabase

## Member Function Documentation

## ◆ authorized()

Signal< std::string > & Wt::Auth::OAuthAuthorizationEndpointProcess::authorized | ( |  | ) |

This signal is emitted when the user has successfully logged in.

When the user has successfully logged in and the request is valid, this signal will be emitted and the user can be redirected to the redirect URI using authorizeScope.

This signal supplies the scope as argument.

## ◆ authorizeScope()

void Wt::Auth::OAuthAuthorizationEndpointProcess::authorizeScope | ( | const std::string & | scope | ) |

Authorize the given scope and redirect the user.

If the user has successfully logged in this function will redirect the user to the redirect URI with a valid "code" parameter which is only valid for the given scope.

## ◆ processEnvironment()

void Wt::Auth::OAuthAuthorizationEndpointProcess::processEnvironment | ( |  | ) |

Processes the environment and authorizes the user when already logged in.

The authorized() signal should be connected before calling this function.

## ◆ setAuthCodeExpSecs()

void Wt::Auth::OAuthAuthorizationEndpointProcess::setAuthCodeExpSecs | ( | int | seconds | ) |

Sets the amount of seconds after which generated authorization codes expire.

This defaults to 600 seconds.