Nextcloud PHP API (master)

IUserSession

Interface for managing and querying user session state.

Provides methods for authenticating users, accessing the active user, and handling login/logout functionality in a Nextcloud server session.

Tags
since
6.0.0

Table of Contents

Methods

getImpersonatingUserID()  : string|null
Returns the user ID of the impersonator if another user is being impersonated.
getUser()  : IUser|null
Returns the currently authenticated user for this session, or null if the session has no active user.
isLoggedIn()  : bool
Checks whether a user is currently logged in for this session.
login()  : bool
Attempts to authenticate the given user and start a session.
logout()  : void
Logs out the current user and terminates their session.
setImpersonatingUserID()  : void
Sets or clears the impersonator's user ID in the current session.
setUser()  : mixed
Sets the current active user for this session.
setVolatileActiveUser()  : void
Temporarily sets the active user for this session without persisting it in the session storage.

Methods

getImpersonatingUserID()

Returns the user ID of the impersonator if another user is being impersonated.

public getImpersonatingUserID() : string|null
Tags
since
18.0.0
Return values
string|null

The impersonating user's ID, or null if not impersonating.

getUser()

Returns the currently authenticated user for this session, or null if the session has no active user.

public getUser() : IUser|null
Tags
since
8.0.0
Return values
IUser|null

The active user, or null if the session is anonymous, expired, or in incognito mode.

isLoggedIn()

Checks whether a user is currently logged in for this session.

public isLoggedIn() : bool
Tags
since
8.0.0
Return values
bool

True if a user is authenticated and enabled, false otherwise.

login()

Attempts to authenticate the given user and start a session.

public login(string $uid, string $password) : bool
Parameters
$uid : string

The user's unique identifier (username).

$password : string

The user's plain-text password.

Tags
since
6.0.0
Return values
bool

True on successful login, false otherwise.

logout()

Logs out the current user and terminates their session.

public logout() : void

Clears authentication tokens and user-related session data.

Tags
since
6.0.0

setImpersonatingUserID()

Sets or clears the impersonator's user ID in the current session.

public setImpersonatingUserID([bool $useCurrentUser = true ]) : void

Note: This does not initiate impersonation, but only records the identity of the impersonator in the session.

If $useCurrentUser is true (default), records the current user's ID as the impersonator. If false, removes any impersonator information from the session.

Parameters
$useCurrentUser : bool = true

Whether to assign the current user as the impersonator or to clear it.

Tags
since
18.0.0

setUser()

Sets the current active user for this session.

public setUser(IUser|null $user) : mixed

Pass null to clear the active user and log out any existing session.

Parameters
$user : IUser|null

The user to set as active, or null to unset.

Tags
since
8.0.0

setVolatileActiveUser()

Temporarily sets the active user for this session without persisting it in the session storage.

public setVolatileActiveUser(IUser|null $user) : void

Useful for request-scoped user overrides that do not affect the actual session state.

Parameters
$user : IUser|null

The user to set as active, or null to clear.

Tags
since
29.0.0

        
On this page

Search results