Class: 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
Note
This is an abstract class, with methods which must be implemented by a subclass.
The following methods must be implemented: request()
, requestMasterPassword()
Class Hierarchy¶
Subclasses¶
Implementation of credentials interface for the console. |
|
Default implementation of credentials interface. |
|
A generic dialog for requesting credentials. |
Abstract Methods
request a password |
|
request a master password |
Methods
Requests credentials for the specified realm. |
|
Lock the instance against access from multiple threads. |
|
Returns pointer to mutex |
|
Stores the correct username and password for the specified realm. |
|
register instance |
|
Unlock the instance after being locked. |
Static Methods
retrieves instance |
- class qgis.core.QgsCredentials[source]¶
Bases:
object
- get(self, realm: str | None, username: str | None, password: str | None, message: str | None = '', requestCredentials: bool = True)[source]¶
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 ifrequestCredentials
is set to True.The retrieved or user-entered details will be stored in
username
andpassword
.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
- Parameters:
realm (Optional[str])
username (Optional[str])
password (Optional[str])
message (Optional[str] = '')
requestCredentials (bool = True) -> (bool)
- getMasterPassword(self, password: str | None, stored: bool = False)[source]¶
- Parameters:
password (Optional[str])
stored (bool = False) -> (bool)
- static instance() QgsCredentials | None [source]¶
retrieves instance
- Return type:
Optional[QgsCredentials]
- lock(self)[source]¶
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.
- put(self, realm: str | None, username: str | None, password: str | None)[source]¶
Stores the correct
username
andpassword
for the specifiedrealm
.These values will be used for all future calls to
get()
for the samerealm
, without requesting users to re-enter them. It is the caller’s responsibility to ensure that only validusername
andpassword
combinations are used with this method.See also
- Parameters:
realm (Optional[str])
username (Optional[str])
password (Optional[str])
- abstract request(self, realm: str | None, username: str | None, password: str | None, message: str | None = '')[source]¶
request a password
- Parameters:
realm (Optional[str])
username (Optional[str])
password (Optional[str])
message (Optional[str] = '') -> (bool)
- abstract requestMasterPassword(self, password: str | None, stored: bool = False)[source]¶
request a master password
- Parameters:
password (Optional[str])
stored (bool = False) -> (bool)
- setInstance(self, instance: QgsCredentials | None)[source]¶
register instance
- Parameters:
instance (Optional[QgsCredentials])