Wt  3.2.0
Public Member Functions
Wt::Auth::OAuthService Class Reference

An OAuth authorization (and authentication) service provider. More...

#include <Wt/Auth/OAuthService>

Inheritance diagram for Wt::Auth::OAuthService:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 OAuthService (const AuthService &baseAuth)
 Constructor.
virtual ~OAuthService ()
 Destructor.
const AuthServicebaseAuth () const
 Returns the basic authentication service.
virtual OAuthProcesscreateProcess (const std::string &scope) const =0
 Creates a new authorizaiton process.
virtual std::string name () const =0
 Returns the provider name.
virtual WString description () const =0
 Returns the provider description.
virtual int popupWidth () const =0
 Returns the desired width for the popup window.
virtual int popupHeight () const =0
 Returns the desired height for the popup window.
virtual std::string authenticationScope () const =0
 Returns the scope needed for authentication.
virtual std::string redirectEndpoint () const =0
 Returns the redirection endpoint URL.
virtual std::string authorizationEndpoint () const =0
 Returns the authorization endpoint URL.
virtual std::string tokenEndpoint () const =0
 Returns the token endpoint URL.
virtual std::string clientId () const =0
 Returns the client ID.
virtual std::string clientSecret () const =0
 Returns the client secret.
virtual std::string encodeState (const std::string &sessionId) const
 Derives a state value from the session ID.
virtual std::string decodeState (const std::string &state) const
 Validates and decodes a state parameter.
virtual Http::Method tokenRequestMethod () const
 Returns the HTTP method used for the token request.

Detailed Description

An OAuth authorization (and authentication) service provider.

This class implements an OAuth client (2.0 draft), which can be used to allow the user to authorize access to information provided by a third-party OAuth service provider. This allows, among other things, for a user to safely authenticate with your web application without needing to store or even handle his authorization credentials (such as a password), a pattern called "OAuth2 connect".

The OAuth protocol provides a standard for a user to authorize access to protected resources made available by a third party service. The process starts with the user authenticating on an "authorization page" and authorizing access. This results eventually in an access token for the web application. The actual use of this token, to obtain certain information (such as an authenticated identity) from the third party is however not standardized, and there are many other uses of OAuth besides authentication.

Because the focus of the Wt::Auth library is authentication, the OAuth class also contains the implementation for using the access token for authentication (OAuthProcess::getIdentity()).

Like all service classes, this class holds only configuration state. Thus, once configured, it can be safely shared between multiple sessions since its state (the configuration) is read-only. A "const OAuthService" object is thus thread-safe.

The OAuth authorization protocol, including the subsequent use for authentication, consists of a number of consecutive steps, some of which require user interaction, and some which require the use of remote web services. The state machine for this process is implemented in an OAuthProcess. To use OAuth, you need to create such a process and listen for state changes.

Usage example:

 const OAuthService *oauth = ...;

 // Creates an icon which prompts for authentication using this %OAuth service.
 WImage *icon = new WImage(oauth->icon());
 icon->setToolTip(oauth->description());

 // Creates a new process for authentication, which is started by a click on the icon
 process_ = oauth->createProcess(oauth->authenticationScope());
 icon->clicked().connect(process_, &OAuthProcess::startAuthenticate);

 // And capture the result in a method.
 process_->authenticated().connect(this, &MyWidget::oauthDone);

Constructor & Destructor Documentation

Wt::Auth::OAuthService::OAuthService ( const AuthService baseAuth)

Constructor.

Creates a new OAuth service.


Member Function Documentation

virtual std::string Wt::Auth::OAuthService::authenticationScope ( ) const [pure virtual]

Returns the scope needed for authentication.

This returns the scope that is needed (and sufficient) for obtaining identity information, and thus to authenticate the user.

See also:
OAuthProcess::getIdentity(), OAuthProcess::startAuthenticate()

Implemented in Wt::Auth::GoogleService.

virtual std::string Wt::Auth::OAuthService::authorizationEndpoint ( ) const [pure virtual]

Returns the authorization endpoint URL.

This is a remote URL which hosts the OAuth authorization user interface. This URL is loaded in the popup window at the start of an authorization process.

Implemented in Wt::Auth::GoogleService.

virtual std::string Wt::Auth::OAuthService::clientId ( ) const [pure virtual]

Returns the client ID.

This is the identification for this web application with the OAuth authorization server.

Implemented in Wt::Auth::GoogleService.

virtual std::string Wt::Auth::OAuthService::clientSecret ( ) const [pure virtual]

Returns the client secret.

This is the secret credentials for this web application with the OAuth authorization server.

Implemented in Wt::Auth::GoogleService.

virtual OAuthProcess* Wt::Auth::OAuthService::createProcess ( const std::string &  scope) const [pure virtual]

Creates a new authorizaiton process.

This creates a new authorization process for the indicated scope. Valid names for the scope are service provider dependent.

See also:
authenticationScope()

Implemented in Wt::Auth::GoogleService.

std::string Wt::Auth::OAuthService::decodeState ( const std::string &  state) const [virtual]

Validates and decodes a state parameter.

This function returns the sessionId that is encoded in the state, if the signature validates that it is an authentic state generated by encodeState().

virtual WString Wt::Auth::OAuthService::description ( ) const [pure virtual]

Returns the provider description.

This returns a description useful for e.g. tool tips on a login icon.

See also:
name()

Implemented in Wt::Auth::GoogleService.

std::string Wt::Auth::OAuthService::encodeState ( const std::string &  sessionId) const [virtual]

Derives a state value from the session ID.

The state value protects the authorization protocol against misuse, and is used to connect an authorization code response with a particular request.

In the default implementation the state is the sessionId, crytpographically signed. This signature is verified in decodeState().

virtual std::string Wt::Auth::OAuthService::name ( ) const [pure virtual]

Returns the provider name.

This is a short identifier.

See also:
description()

Implemented in Wt::Auth::GoogleService.

virtual int Wt::Auth::OAuthService::popupHeight ( ) const [pure virtual]

Returns the desired height for the popup window.

See also:
popupWidth()

Implemented in Wt::Auth::GoogleService.

virtual int Wt::Auth::OAuthService::popupWidth ( ) const [pure virtual]

Returns the desired width for the popup window.

See also:
popupHeight()

Implemented in Wt::Auth::GoogleService.

virtual std::string Wt::Auth::OAuthService::redirectEndpoint ( ) const [pure virtual]

Returns the redirection endpoint URL.

This is the local URL to which the browser is redirect from the service provider, after the authorization process. You need to configure this URL with the third party authentication service.

A static resource will be deployed at this URL.

See also:
WServer::addResource()

Implemented in Wt::Auth::GoogleService.

virtual std::string Wt::Auth::OAuthService::tokenEndpoint ( ) const [pure virtual]

Returns the token endpoint URL.

This is a remote URL which hosts a web-service that generates access tokens.

Implemented in Wt::Auth::GoogleService.

Http::Method Wt::Auth::OAuthService::tokenRequestMethod ( ) const [virtual]

Returns the HTTP method used for the token request.

While the current OAuth 2.0 draft mandates the use of POST, some implementations (like Facebook) use URL-encoding and a GET request.

The default implementation returns Http::Post (corresponding to the current draft).

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator

Generated on Tue Nov 29 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.5.1