PolkitAgent.Session

g GObject.Object GObject.Object PolkitAgent.Session PolkitAgent.Session GObject.Object->PolkitAgent.Session

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new (identity, cookie)

cancel ()

initiate ()

response (response)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

cookie

str

r/w/co

The cookie obtained from the PolicyKit daemon

identity

Polkit.Identity

r/w/co

The identity to authenticate

Signals

Inherited:

GObject.Object (1)

Name

Short Description

completed

Emitted when the authentication session has been completed or cancelled.

request

Emitted when the user is requested to answer a question.

show-error

Emitted when there is information related to an error condition to be displayed to the user.

show-info

Emitted when there is information to be displayed to the user.

Fields

Inherited:

GObject.Object (1)

Class Details

class PolkitAgent.Session(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

PolkitAgent.SessionClass

The PolkitAgent.Session class is an abstraction used for interacting with the native authentication system (for example PAM) for obtaining authorizations. This class is typically used together with instances that are derived from the PolkitAgent.Listener abstract base class.

To perform the actual authentication, PolkitAgent.Session uses a trusted suid helper. The authentication conversation is done through a pipe. This is transparent; the user only need to handle the PolkitAgent.Session ::request, PolkitAgent.Session ::show-info, PolkitAgent.Session ::show-error and PolkitAgent.Session ::completed signals and invoke PolkitAgent.Session.response() in response to requests.

If the user successfully authenticates, the authentication helper will invoke a method on the PolicyKit daemon (see Polkit.Authority.authentication_agent_response_sync()) with the given cookie. Upon receiving a positive response from the PolicyKit daemon (via the authentication helper), the PolkitAgent.Session ::completed signal will be emitted with the gained_authorization paramter set to True.

If the user is unable to authenticate, the PolkitAgent.Session ::completed signal will be emitted with the gained_authorization paramter set to False.

classmethod new(identity, cookie)
Parameters:
  • identity (Polkit.Identity) – The identity to authenticate.

  • cookie (str) – The cookie obtained from the PolicyKit daemon

Returns:

A PolkitAgent.Session. Free with GObject.Object.unref().

Return type:

PolkitAgent.Session

Creates a new authentication session.

The caller should connect to the PolkitAgent.Session ::request, PolkitAgent.Session ::show-info, PolkitAgent.Session ::show-error and PolkitAgent.Session ::completed signals and then call PolkitAgent.Session.initiate() to initiate the authentication session.

cancel()

Cancels an authentication session. This will make self emit the PolkitAgent.Session ::completed signal.

initiate()

Initiates the authentication session. Before calling this method, make sure to connect to the various signals. The signals will be emitted in the thread-default main loop that this method is invoked from.

Use PolkitAgent.Session.cancel() to cancel the session.

response(response)
Parameters:

response (str) – Response from the user, typically a password.

Function for providing response to requests received via the PolkitAgent.Session ::request signal.

Signal Details

PolkitAgent.Session.signals.completed(session, gained_authorization)
Signal Name:

completed

Flags:

RUN_LAST

Parameters:
  • session (PolkitAgent.Session) – The object which received the signal

  • gained_authorization (bool) – True only if the authorization was successfully obtained.

Emitted when the authentication session has been completed or cancelled. The gained_authorization parameter is True only if the user successfully authenticated.

Upon receiving this signal, the user should free session using GObject.Object.unref().

PolkitAgent.Session.signals.request(session, request, echo_on)
Signal Name:

request

Flags:

RUN_LAST

Parameters:
  • session (PolkitAgent.Session) – The object which received the signal

  • request (str) – The request to show the user, e.g. “name: “ or “password: “.

  • echo_on (bool) – True if the response to the request SHOULD be echoed on the screen, False if the response MUST NOT be echoed to the screen.

Emitted when the user is requested to answer a question.

When the response has been collected from the user, call PolkitAgent.Session.response().

PolkitAgent.Session.signals.show_error(session, text)
Signal Name:

show-error

Flags:

RUN_LAST

Parameters:
  • session (PolkitAgent.Session) – The object which received the signal

  • text (str) – An error string to display to the user.

Emitted when there is information related to an error condition to be displayed to the user.

PolkitAgent.Session.signals.show_info(session, text)
Signal Name:

show-info

Flags:

RUN_LAST

Parameters:
  • session (PolkitAgent.Session) – The object which received the signal

  • text (str) – A string to display to the user.

Emitted when there is information to be displayed to the user.

Property Details

PolkitAgent.Session.props.cookie
Name:

cookie

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The cookie obtained from the PolicyKit daemon

PolkitAgent.Session.props.identity
Name:

identity

Type:

Polkit.Identity

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The identity to authenticate.