1#ifndef TENDUKE_OIDC_OIDCSESSIONIMPL_H
2#define TENDUKE_OIDC_OIDCSESSIONIMPL_H
4#include "./OIDCLogin.h"
5#include "./OIDCSession.h"
6#include "./OIDCSessionEventListener.h"
7#include "../OIDCState.h"
8#include "../OIDCClient.h"
51 std::unique_ptr<tenduke::oidc::OIDCState>
state,
52 const std::shared_ptr<const tenduke::oidc::OIDCLogin> &
oidc,
53 const std::shared_ptr<const tenduke::oidc::OIDCClient> &
oidcClient,
54 const std::shared_ptr<tenduke::time::Clock> &
clock,
55 const std::shared_ptr<::tenduke::oidc::OIDCSessionEventListener> &eventListener =
nullptr,
65 std::shared_ptr<const tenduke::oidc::OIDCState>
getOIDCState()
override;
82 bool isValidAt(std::int64_t expiresAt)
const;
103 std::shared_ptr<tenduke::oidc::OIDCState>
state;
121 const std::shared_ptr<tenduke::time::Clock>
clock;
123 const std::shared_ptr<const tenduke::oidc::OIDCLogin>
oidc;
125 const std::shared_ptr<const tenduke::oidc::OIDCClient>
oidcClient;
127 const std::shared_ptr<tenduke::oidc::OIDCSessionEventListener>
notify;
OIDCSessionImpl(std::unique_ptr< tenduke::oidc::OIDCState > state, const std::shared_ptr< const tenduke::oidc::OIDCLogin > &oidc, const std::shared_ptr< const tenduke::oidc::OIDCClient > &oidcClient, const std::shared_ptr< tenduke::time::Clock > &clock, const std::shared_ptr<::tenduke::oidc::OIDCSessionEventListener > &eventListener=nullptr, uint64_t validitySafetyMarginS=DEFAULT_SAFETY_MARGIN_S, std::chrono::milliseconds loginTimeout=DEFAULT_SESSION_LOGIN_TIMEOUT)
Constructs new instance.
Definition OIDCSessionImpl.cpp:277
bool isValidAt(std::int64_t expiresAt) const
Checks if a token expiring at expiresAt (epoch seconds) is still valid, minding the safety margin,...
Definition OIDCSessionImpl.cpp:130
virtual void login()
Performs login.
Definition OIDCSessionImpl.cpp:162
bool heartbeat() override
Executes a heartbeat with the backend, checking that the current access token really works.
Definition OIDCSessionImpl.cpp:259
std::shared_ptr< tenduke::oidc::OIDCState > state
The OIDC-state.
Definition OIDCSessionImpl.h:103
const std::shared_ptr< tenduke::oidc::OIDCSessionEventListener > notify
Listener for OIDC session events.
Definition OIDCSessionImpl.h:127
const std::chrono::milliseconds loginTimeout
Login timeout.
Definition OIDCSessionImpl.h:107
const std::uint64_t validitySafetyMarginS
Safety margin in seconds for checking if access token has expired.
Definition OIDCSessionImpl.h:112
bool abortRequested
Set by abortLogin(), cleared when a login starts.
Definition OIDCSessionImpl.h:100
void invalidate() override
Invalidates the session.
Definition OIDCSessionImpl.cpp:73
void abortLogin() override
Aborts an ongoing login flow.
Definition OIDCSessionImpl.cpp:27
std::shared_ptr< tenduke::oidc::OIDCLoginRequest > loginRequest
Current login request.
Definition OIDCSessionImpl.h:105
static const std::uint64_t DEFAULT_SAFETY_MARGIN_S
Default safety margin in seconds for checking access token expiration.
Definition OIDCSessionImpl.h:30
bool isValid() override
Checks that local session is valid.
Definition OIDCSessionImpl.cpp:79
virtual void refreshOrLogin()
Performs either refresh, or if it fails, new login.
Definition OIDCSessionImpl.cpp:141
virtual bool hasRefreshableState()
Checks if the session has state, which can be refreshed.
Definition OIDCSessionImpl.cpp:44
void ensureValidSession() override
Checks that the OIDC session is valid, but if it is NOT, either refreshes the access token or authent...
Definition OIDCSessionImpl.cpp:62
const std::shared_ptr< tenduke::time::Clock > clock
Clock for checking session validity locally.
Definition OIDCSessionImpl.h:121
void recordTokenLifetime()
Records the lifetime of the token just received, i.e.
Definition OIDCSessionImpl.cpp:108
bool tokenLifetimeKnown
true if tokenLifetimeS is known.
Definition OIDCSessionImpl.h:118
void refresh() override
Forces refresh of the session.
Definition OIDCSessionImpl.cpp:235
std::string getAccessToken() override
Returns access token of the session.
Definition OIDCSessionImpl.cpp:49
const std::shared_ptr< const tenduke::oidc::OIDCClient > oidcClient
The OIDC-client.
Definition OIDCSessionImpl.h:125
OIDCSessionImpl(std::unique_ptr< tenduke::oidc::OIDCState > state, const std::shared_ptr< const tenduke::oidc::OIDCLogin > &oidc, const std::shared_ptr< const tenduke::oidc::OIDCClient > &oidcClient, const std::shared_ptr< tenduke::time::Clock > &clock, const std::shared_ptr<::tenduke::oidc::OIDCSessionEventListener > &eventListener=nullptr, uint64_t validitySafetyMarginS=DEFAULT_SAFETY_MARGIN_S, std::chrono::milliseconds loginTimeout=DEFAULT_SESSION_LOGIN_TIMEOUT)
Constructs new instance.
Definition OIDCSessionImpl.cpp:277
std::shared_ptr< const tenduke::oidc::OIDCState > getOIDCState() override
Returns the current OIDC-state for inspection.
Definition OIDCSessionImpl.cpp:57
void reEstablish() override
Re-establishes the session: Tries first to refresh the state, if it fails, re-authenticates the user.
Definition OIDCSessionImpl.cpp:230
std::mutex loginMutex
Guards loginRequest and abortRequested.
Definition OIDCSessionImpl.h:98
const std::shared_ptr< const tenduke::oidc::OIDCLogin > oidc
Service to perform OIDC login.
Definition OIDCSessionImpl.h:123
std::uint64_t effectiveSafetyMarginS() const
Returns the safety margin in seconds: validitySafetyMarginS, capped to half of the token lifetime if ...
Definition OIDCSessionImpl.cpp:122
virtual std::int64_t getTokenExpiresAt() const
Returns expiration time (epoch seconds) of the token, which determines validity of this session.
Definition OIDCSessionImpl.cpp:100
std::uint64_t tokenLifetimeS
Lifetime in seconds of the current token, recorded when the token was received.
Definition OIDCSessionImpl.h:116
Stateful service to manage OIDC-session.
Definition OIDCSession.h:23
Implementation of OpenID Connect protocol.
Definition AutoDiscovery.h:17
const std::chrono::milliseconds DEFAULT_SESSION_LOGIN_TIMEOUT
Default login timeout.
Definition OIDCSessionImpl.h:18
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4