10Duke Enterprise C++ Client
|
10Duke Enterprise supports identity-based licensing for users: Users authenticate themselves and every operation tracks the user's identity. For authentication, 10Duke Enterprise uses Open ID Connect (OIDC), which is an authentication framework built on OAuth 2. To use identity-based licensing, you need an OIDC-based identity provider service. If you don't have one configured, contact our sales for options.
10Duke Enterprise C++ client provides following types of OIDC authentication:
In all cases, the client manages the login session automatically whenever API-method needing authorization is used:
Application developer does not need to explicitly start login or refresh the session. You can register a callback, which gets notified, when certain login-related events (e.g. login is starting) happen, see Registering session event listener for details.
See also the client concepts. Our official documentation has an overview of identity-based licensing.
To create the client for browser-based authentication:
tenduke::ee::createClientUsingAutodiscovery(const std::string &,const tenduke::ee::ClientProperties &,const std::string &,const tenduke::oidc::osbrowser::BrowserAuthenticationConfig &,const std::string &,const tenduke::ServiceConfiguration &)
To create the client for device authentication, use factory functions:
tenduke::ee::createClientForDeviceUsingAutodiscovery(const std::string &,const tenduke::ee::ClientProperties &,const std::string &,const tenduke::oidc::device::DeviceAuthenticationConfig &,const std::string &,const tenduke::ServiceConfiguration &)
tenduke::ee::createClientForDevice(const std::string &,const tenduke::ee::ClientProperties &,const std::string &,const tenduke::oauth::OAuthBackendConfiguration &,const tenduke::oidc::OIDCConfiguration &,const tenduke::oidc::device::DeviceAuthenticationConfig &,const std::string &,const tenduke::ServiceConfiguration &)
To create the client for Client Credentials Grant, use methods from factory tenduke::ee::CCGClientFactory
To create the client for Resource Owner Password Credentials grant, use methods from factory tenduke::ee::ROPGClientFactory
.
Note the following client limitations:
All these work with 10Duke Identity Provider.
10Duke Enterprise C++ client provides default browser-based OIDC authentication using operating system default browser and "loopback interface redirection": When user needs to be authenticated, the client opens default OS-browser and starts the login flow with the OIDC-provider. The client simultaneously opens a simple local HTTP-server, which is used to detect when the login is complete: When the login is complete, the OIDC server will issue HTTP-redirect to a pre-configured URL (the redirect-uri) in the browser. For details see RFC 8252: 7.3 Loopback Interface Redirection.
The client has to be configured with HTTP-message, which is served by the HTTP-server after the login is complete. This HTTP message is full HTTP-response, with status line, headers and response message entity. This allows e.g. using HTTP-redirect to navigate the browser to a external site after login.
For example, to create client for browser-based authentication:
Note that the redirect uri must start with http://localhost
.
If the device, where the client is running, does not have a browser, or using the browser is awkward, the authentication can be done using "Device Authorization Grant", aka. device flow. To start the user login, the device shows an authentication URL and so called "user code" to the user. Using another device (e.g. computer or tablet), the user starts authentication by navigating to the given URL and entering the user code. Once the authentication is complete, the client is notified and user session is set up.
For details of the Device Authorization Grant, see RFC 8628.
When authenticating with device flow, the client has to be configured with a callback, which is called when the client needs to display the URL where user must navigate. The application developer has to implement the display of the information.
Example:
If the entity to be authenticated is device or server, one possibility is to use OAuth Client Credentials Grant. The authenticated actor is the OAuth client, not a user, and because of this the ID-token is not available. This is by design.
Our developer guide has a section describing the Client Credentials Grant. For further details, like use cases or how to configure the backend for Client Credentials Grant, contact 10Duke support.
To set up the client to authenticate with Client Credentials:
We do not recommend using OAuth Resource Owner Password Credentials Grant and this grant is disallowed in OAuth 2.0 Security Best Current Practice.
To use this authentication method, create implementation of tenduke::oauth::ropg::ResourceOwnerPasswordCredentialsProvider
and register instance of it when creating the client (see below for example). As the client maintains the state automatically, when the client determines that the user needs to log in, it executes the callback to provide the authentication credentials.
If the authentication fails because of invalid credentials, the client internally retries the authentication request by first executing the callback again and then re-executing the request with the new credentials. The client has maximum number of retries after which the client throws tenduke::oauth::OAuthInvalidGrant
. The maximum number of retries can be configured when creating the client.
Our developer guide has a section about the Resource Owner Password Credentials Grant.
To create client, which authenticates the user with Resource Owner Password Credentials Grant:
The client manages the user login session automatically by performing login (either by opening browser or by device flow callback) when you use API which needs valid user login session and the user has not yet logged in or when th login session has expired. The client also refreshes the login session automatically, when required. The application developer does not need to trigger login manually.
You might want to be notified, when login is starting, login is complete or the user session has been refreshed. For example, when login is complete, you might want to bring your application on top of all other windows: in browser login, the browser usually opens on top and you want to bring the user back to your application.
To get the notifications, register instance of tenduke::oidc::OIDCSessionEventListener
when creating the client. You can also inherit from tenduke::oidc::DefaultOIDCSessionEventListener
, which has empty default implementations for all the callback methods. To configure the listener, use parameter oidcSessionConfiguration
in the OIDC authentication configuration, see below for examples.
A sample listener:
When creating a client for browser-authentication, register the listener using parameter oidcSessionConfiguration
of tenduke::oidc::osbrowser::BrowserAuthenticationConfig
:
For fully working sample, see identity_based_client_example.cpp
under examples.
Here are some examples on how to work with the client. For further details and complete API documentation, see tenduke::ee::TendukeClient
.
Checkout licenses:
Renew leases of the checked out licenses: (NOTE: Renewal changes the lease ids. The returned leases replace the original leases.)
To release the licenses (NOTE Renewal has changed the lease ids.)
Get current OAuth access-token for authenticating requests to other 10Duke Enterprise APIs: