Albert
Loading...
Searching...
No Matches
albert::util::OAuth2 Class Reference

#include <albert/oauth.h>

Inherits QObject.

Detailed Description

Provides OAuth2 authentication with support for the Authorization Code Flow with PKCE and refresh tokens.

Public Types

enum class  State { NotAuthorized , Awaiting , Granted }
 

Signals

void clientIdChanged (const QString &)
 Emitted when the client ID changes.
 
void clientSecretChanged (const QString &)
 Emitted when the client secret changes.
 
void scopeChanged (const QString &)
 Emitted when the scope changes.
 
void authUrlChanged (const QString &)
 Emitted when the authorization URL changes.
 
void redirectUriChanged (const QString &)
 Emitted when the redirect URI changes.
 
void tokenUrlChanged (const QString &)
 Emitted when the token URL changes.
 
void tokensChanged ()
 Emitted when the access token, refresh token or expiration date changes.
 
void stateChanged (State)
 Emitted when the state changes.
 

Public Member Functions

 OAuth2 ()
 
 ~OAuth2 ()
 
void requestAccess ()
 Requests access, i.e. starts the Authorization Code Flow to obtain an access token.
 
void updateTokens ()
 Updates the access token.
 
const QString & clientId () const
 Returns the client identifier.
 
void setClientId (const QString &id)
 Sets the client identifier to id.
 
const QString & clientSecret () const
 Returns the client secret.
 
void setClientSecret (const QString &secret)
 Sets the client secret to secret.
 
const QString & scope () const
 Returns the OAuth scope to request permissions for.
 
void setScope (const QString &scope)
 Sets the OAuth scope to request permissions for to scope.
 
const QString & authUrl () const
 Returns the authorization URL.
 
void setAuthUrl (const QString &url)
 Sets the authorization URL to url.
 
const QString & redirectUri () const
 Returns the redirect URI.
 
void setRedirectUri (const QString &uri)
 Sets the redirect URI to uri.
 
bool isPkceEnabled () const
 Returns true if PKCE is enabled, false otherwise.
 
void setPkceEnabled (bool enabled)
 Sets whether PKCE is enabled or not.
 
const QString & tokenUrl () const
 Returns the token URL.
 
void setTokenUrl (const QString &url)
 Sets the token URL to url.
 
const QString & accessToken () const
 Returns the access token.
 
const QString & refreshToken () const
 Returns the access token.
 
const QDateTime & tokenExpiration () const
 Returns the access token.
 
void setTokens (const QString &access_token, const QString &refresh_token={}, const QDateTime &expiration={})
 Sets the access token, refresh token and expiration date.
 
const QString & error () const
 Returns the error message if any.
 
State state () const
 Returns the state of the authorization flow.
 
void handleCallback (const QUrl &callback)
 Handles the redirect callback URL from the OAuth2 provider.
 

Member Enumeration Documentation

◆ State

enum class albert::util::OAuth2::State
strong
Enumerator
NotAuthorized 

Not yet authorized.

Awaiting 

Waiting for user interaction to authorize.

Granted 

Authorization granted and access token available.

Constructor & Destructor Documentation

◆ OAuth2()

albert::util::OAuth2::OAuth2 ( )

◆ ~OAuth2()

albert::util::OAuth2::~OAuth2 ( )

Member Function Documentation

◆ accessToken()

const QString & albert::util::OAuth2::accessToken ( ) const

Returns the access token.

◆ authUrl()

const QString & albert::util::OAuth2::authUrl ( ) const

Returns the authorization URL.

◆ authUrlChanged

void albert::util::OAuth2::authUrlChanged ( const QString &  )
signal

Emitted when the authorization URL changes.

◆ clientId()

const QString & albert::util::OAuth2::clientId ( ) const

Returns the client identifier.

◆ clientIdChanged

void albert::util::OAuth2::clientIdChanged ( const QString &  )
signal

Emitted when the client ID changes.

◆ clientSecret()

const QString & albert::util::OAuth2::clientSecret ( ) const

Returns the client secret.

◆ clientSecretChanged

void albert::util::OAuth2::clientSecretChanged ( const QString &  )
signal

Emitted when the client secret changes.

◆ error()

const QString & albert::util::OAuth2::error ( ) const

Returns the error message if any.

◆ handleCallback()

void albert::util::OAuth2::handleCallback ( const QUrl &  callback)

Handles the redirect callback URL from the OAuth2 provider.

◆ isPkceEnabled()

bool albert::util::OAuth2::isPkceEnabled ( ) const

Returns true if PKCE is enabled, false otherwise.

◆ redirectUri()

const QString & albert::util::OAuth2::redirectUri ( ) const

Returns the redirect URI.

◆ redirectUriChanged

void albert::util::OAuth2::redirectUriChanged ( const QString &  )
signal

Emitted when the redirect URI changes.

◆ refreshToken()

const QString & albert::util::OAuth2::refreshToken ( ) const

Returns the access token.

◆ requestAccess()

void albert::util::OAuth2::requestAccess ( )

Requests access, i.e. starts the Authorization Code Flow to obtain an access token.

◆ scope()

const QString & albert::util::OAuth2::scope ( ) const

Returns the OAuth scope to request permissions for.

◆ scopeChanged

void albert::util::OAuth2::scopeChanged ( const QString &  )
signal

Emitted when the scope changes.

◆ setAuthUrl()

void albert::util::OAuth2::setAuthUrl ( const QString &  url)

Sets the authorization URL to url.

◆ setClientId()

void albert::util::OAuth2::setClientId ( const QString &  id)

Sets the client identifier to id.

◆ setClientSecret()

void albert::util::OAuth2::setClientSecret ( const QString &  secret)

Sets the client secret to secret.

◆ setPkceEnabled()

void albert::util::OAuth2::setPkceEnabled ( bool  enabled)

Sets whether PKCE is enabled or not.

◆ setRedirectUri()

void albert::util::OAuth2::setRedirectUri ( const QString &  uri)

Sets the redirect URI to uri.

◆ setScope()

void albert::util::OAuth2::setScope ( const QString &  scope)

Sets the OAuth scope to request permissions for to scope.

◆ setTokens()

void albert::util::OAuth2::setTokens ( const QString &  access_token,
const QString &  refresh_token = {},
const QDateTime &  expiration = {} 
)

Sets the access token, refresh token and expiration date.

◆ setTokenUrl()

void albert::util::OAuth2::setTokenUrl ( const QString &  url)

Sets the token URL to url.

◆ state()

State albert::util::OAuth2::state ( ) const

Returns the state of the authorization flow.

◆ stateChanged

void albert::util::OAuth2::stateChanged ( State  )
signal

Emitted when the state changes.

◆ tokenExpiration()

const QDateTime & albert::util::OAuth2::tokenExpiration ( ) const

Returns the access token.

◆ tokensChanged

void albert::util::OAuth2::tokensChanged ( )
signal

Emitted when the access token, refresh token or expiration date changes.

◆ tokenUrl()

const QString & albert::util::OAuth2::tokenUrl ( ) const

Returns the token URL.

◆ tokenUrlChanged

void albert::util::OAuth2::tokenUrlChanged ( const QString &  )
signal

Emitted when the token URL changes.

◆ updateTokens()

void albert::util::OAuth2::updateTokens ( )

Updates the access token.


The documentation for this class was generated from the following file: