Class: QgsCredentials

class qgis.core.QgsCredentials

Bases: sip.wrapper

Constructor for QgsCredentials.

Interface for requesting credentials in QGIS in GUI independent way.

This class provides abstraction of a dialog for requesting credentials to the user. By default QgsCredentials will be used if not overridden with other credential creator function.

QGIS application uses QgsCredentialDialog class for displaying a dialog to the user.

Caller can use the mutex to synchronize authentications to avoid requesting credentials for the same resource several times.

Object deletes itself when it’s not needed anymore. Children should use signal destroyed() to be notified of the deletion

Methods

get

Requests credentials for the specified realm.

getMasterPassword

param password

instance

retrieves instance

lock

Lock the instance against access from multiple threads.

mutex

Returns pointer to mutex

put

Stores the correct username and password for the specified realm.

request

request a password

requestMasterPassword

request a master password

setInstance

register instance

unlock

Unlock the instance after being locked.

get(self, realm: str, username: str, password: str, message: str = '') Tuple[bool, str, str]

Requests credentials for the specified realm.

If existing credentials exist for the given realm, these will be returned. Otherwise the credential handler will prompt for the correct username and password.

The retrieved or user-entered details will be stored in username and password.

Optionally, a specific message can be used to advise users of the context for the credentials request.

Note

This method will not automatically store the newly obtained credentials. Callers must manually call put() after verifying that the obtained credentials are correct.

See also

put()

Parameters
  • realm (str) –

  • username (str) –

  • password (str) –

  • message (str = '') –

Return type

Tuple[bool, str, str]

getMasterPassword(self, password: str, stored: bool = False) Tuple[bool, str]
Parameters
  • password (str) –

  • stored (bool = False) –

Return type

Tuple[bool, str]

instance() QgsCredentials

retrieves instance

Return type

QgsCredentials

lock(self)

Lock the instance against access from multiple threads. This does not really lock access to get/put methods, it will just prevent other threads to lock the instance and continue the execution. When the class is used from non-GUI threads, they should call lock() before the get/put calls to avoid race conditions.

New in version 2.4.

mutex(self) QMutex

Returns pointer to mutex

New in version 2.4.

Return type

QMutex

put(self, realm: str, username: str, password: str)

Stores the correct username and password for the specified realm.

These values will be used for all future calls to get() for the same realm, without requesting users to re-enter them. It is the caller’s responsibility to ensure that only valid username and password combinations are used with this method.

See also

get()

Parameters
  • realm (str) –

  • username (str) –

  • password (str) –

request(self, realm: str, username: str, password: str, message: str = '') Tuple[bool, str, str]

request a password

Parameters
  • realm (str) –

  • username (str) –

  • password (str) –

  • message (str = '') –

Return type

Tuple[bool, str, str]

requestMasterPassword(self, password: str, stored: bool = False) Tuple[bool, str]

request a master password

Parameters
  • password (str) –

  • stored (bool = False) –

Return type

Tuple[bool, str]

setInstance(self, instance: QgsCredentials)

register instance

Parameters

instance (QgsCredentials) –

unlock(self)

Unlock the instance after being locked.

New in version 2.4.