ImagingTools Core SDK
Classes | Public Member Functions | List of all members
imtauth::IPersonalAccessTokenManagerabstract

#include <IPersonalAccessTokenManager.h>

Inherits iser::ISerializable.

Inherited by imtauth::CPersonalAccessTokenManagerComp [virtual], and imtauthgql::CClientRequestPersonalAccessTokenManagerComp [virtual].

Classes

struct  TokenCreationResult
 

Public Member Functions

virtual TokenCreationResult CreateToken (const QByteArray &userId, const QString &name, const QString &description, const QByteArrayList &scopes, const QDateTime &expiresAt)=0
 
virtual bool ValidateToken (const QByteArray &rawToken, QByteArray &userId, QByteArray &tokenId, QByteArrayList &scopes) const =0
 
virtual QByteArrayList GetTokenIds (const QByteArray &userId) const =0
 
virtual IPersonalAccessTokenSharedPtr GetToken (const QByteArray &tokenId) const =0
 
virtual bool RevokeToken (const QByteArray &tokenId)=0
 
virtual bool UpdateLastUsedAt (const QByteArray &tokenId)=0
 
virtual bool DeleteToken (const QByteArray &tokenId)=0
 

Detailed Description

Interface for managing personal access tokens.

This interface provides operations for creating, validating, revoking, and managing personal access tokens (PATs) for API authentication. Tokens are securely generated and stored as SHA-256 hashes for security.

Implements IChangeable to notify observers when tokens are created, revoked, or deleted.

Definition at line 28 of file IPersonalAccessTokenManager.h.

Member Function Documentation

◆ CreateToken()

virtual TokenCreationResult imtauth::IPersonalAccessTokenManager::CreateToken ( const QByteArray &  userId,
const QString &  name,
const QString &  description,
const QByteArrayList &  scopes,
const QDateTime &  expiresAt 
)
pure virtual

Create a new personal access token.

Generates a cryptographically secure random token, hashes it with SHA-256, and stores it in the collection. The raw token value is returned only once and should be saved by the caller as it cannot be retrieved later.

Parameters
userIdUser ID who owns the token
nameHuman-readable name for the token
descriptionDescription of the token's purpose
scopesList of permission scopes to grant to this token
expiresAtOptional expiration timestamp (invalid QDateTime for no expiration)
Returns
TokenCreationResult containing the token ID and raw token value

◆ DeleteToken()

virtual bool imtauth::IPersonalAccessTokenManager::DeleteToken ( const QByteArray &  tokenId)
pure virtual

Delete a personal access token.

Permanently removes the token from the collection. This operation cannot be undone. Consider using RevokeToken() instead for audit trail purposes.

Parameters
tokenIdToken ID to delete
Returns
True if token was deleted successfully, false if token not found

◆ GetToken()

virtual IPersonalAccessTokenSharedPtr imtauth::IPersonalAccessTokenManager::GetToken ( const QByteArray &  tokenId) const
pure virtual

Get token information by token ID.

Returns a copy of the token object with all metadata except the raw token value (which is never stored or retrievable).

Parameters
tokenIdToken ID to retrieve
Returns
Shared pointer to token object, or nullptr if not found

◆ GetTokenIds()

virtual QByteArrayList imtauth::IPersonalAccessTokenManager::GetTokenIds ( const QByteArray &  userId) const
pure virtual

Get list of token IDs for a specific user.

Parameters
userIdUser ID to get tokens for
Returns
List of token IDs owned by the user

◆ RevokeToken()

virtual bool imtauth::IPersonalAccessTokenManager::RevokeToken ( const QByteArray &  tokenId)
pure virtual

Revoke a personal access token.

Marks the token as revoked, immediately invalidating it for authentication. The token remains in the collection for audit purposes but cannot be used.

Parameters
tokenIdToken ID to revoke
Returns
True if token was revoked successfully, false if token not found

◆ UpdateLastUsedAt()

virtual bool imtauth::IPersonalAccessTokenManager::UpdateLastUsedAt ( const QByteArray &  tokenId)
pure virtual

Update the last used timestamp for a token.

Records when the token was last successfully used for authentication. This information can be used for monitoring and security auditing.

Parameters
tokenIdToken ID to update
Returns
True if timestamp was updated successfully, false if token not found

◆ ValidateToken()

virtual bool imtauth::IPersonalAccessTokenManager::ValidateToken ( const QByteArray &  rawToken,
QByteArray &  userId,
QByteArray &  tokenId,
QByteArrayList &  scopes 
) const
pure virtual

Validate a personal access token.

Checks if the provided token is valid by comparing its hash against stored hashes. Validates that the token is not revoked and not expired. Uses constant-time comparison to prevent timing attacks.

Parameters
rawTokenPlain text token value to validate
[out]userIdUser ID associated with the token (if valid)
[out]tokenIdToken ID associated with the token (if valid)
[out]scopesPermission scopes granted to the token (if valid)
Returns
True if token is valid, false if invalid, revoked, or expired