Session

class OC\User\Session
Class Session
Hooks available in scope \OC\User:
- preSetPassword(\OC\User\User $user, string $password, string $recoverPassword)
- postSetPassword(\OC\User\User $user, string $password, string $recoverPassword)
- preDelete(\OC\User\User $user)
- postDelete(\OC\User\User $user)
- preCreateUser(string $uid, string $password)
- postCreateUser(\OC\User\User $user)
- assignedUserId(string $uid)
- preUnassignedUserId(string $uid)
- postUnassignedUserId(string $uid)
- preLogin(string $user, string $password)
- postLogin(\OC\User\User $user, string $loginName, string $password, boolean $isTokenLogin)
- preRememberedLogin(string $uid)
- postRememberedLogin(\OC\User\User $user)
- logout()
- postLogout()
Source:lib/private/User/Session.php#92
Implements:OCP\IUserSession OC\Hooks\Emitter

Properties

protected static property OC\User\Session::$activeUser
Source:lib/private/User/Session.php#110
Type:\OC\User\User

Methods

public OC\User\Session::__construct($manager, $session, $timeFactory, $tokenProvider, $config, $random, $lockdownManager, $logger, $dispatcher)
Source:

lib/private/User/Session.php#133

Parameters:
public OC\User\Session::setTokenProvider($provider)
Source:

lib/private/User/Session.php#157

Parameters:
public OC\User\Session::listen($scope, $method, $callback)
Source:

lib/private/User/Session.php#166

Parameters:
  • $scope (string)
  • $method (string)
  • $callback (callable)
public OC\User\Session::removeListener($scope=null, $method=null, $callback=null)
Source:

lib/private/User/Session.php#175

Parameters:
  • $scope (string) optional
  • $method (string) optional
  • $callback (callable) optional
public OC\User\Session::getManager()
get the manager object
Source:lib/private/User/Session.php#184
Returns:\OC\User\Manager | \OC\Hooks\PublicEmitter
public OC\User\Session::getSession()
get the session object
Source:lib/private/User/Session.php#193
Returns:\OCP\ISession
public OC\User\Session::setSession($session)
set the session object
Source:

lib/private/User/Session.php#202

Parameters:
public OC\User\Session::setUser($user)
set the currently active user
Source:

lib/private/User/Session.php#215

Parameters:
public OC\User\Session::getUser()
get the current active user
Source:lib/private/User/Session.php#229
Returns:\OCP\IUser | null Current user, otherwise null
protected OC\User\Session::validateSession()
Validate whether the current session is valid
- For token-authenticated clients, the token validity is checked
- For browsers, the session token validity is checked
Source:lib/private/User/Session.php#255
public OC\User\Session::isLoggedIn()
Checks whether the user is logged in
Source:lib/private/User/Session.php#280
Returns:bool if logged in
public OC\User\Session::setLoginName($loginName)
set the login name
Source:

lib/private/User/Session.php#294

Parameters:
  • $loginName (string | null) for the logged in user
public OC\User\Session::getLoginName()
get the login name of the current user
Source:lib/private/User/Session.php#307
Returns:string
public OC\User\Session::getImpersonatingUserID()
Source:lib/private/User/Session.php#324
Returns:null | string
public OC\User\Session::setImpersonatingUserID($useCurrentUser=true)
Source:lib/private/User/Session.php#328
protected OC\User\Session::setToken($token)
set the token id
Source:

lib/private/User/Session.php#346

Parameters:
  • $token (int | null) that was used to log in
public OC\User\Session::login($uid, $password)
try to log in with the provided credentials
Source:

lib/private/User/Session.php#362

Parameters:
  • $uid (string)
  • $password (string)
Returns:

bool | null

Throws:

\OC\User\LoginException

public OC\User\Session::completeLogin($user, $loginDetails, $regenerateSessionId=true)
Source:

lib/private/User/Session.php#377

Parameters:
  • $user (OCP\IUser)
  • $loginDetails (array)
  • $regenerateSessionId (bool)
Returns:

bool returns true if login successful or an exception otherwise

Throws:

\OC\User\LoginException

public OC\User\Session::logClientIn($user, $password, $request, $throttler)
Tries to log in a client
Checks token auth enforced
Checks 2FA enabled
Source:

lib/private/User/Session.php#437

Parameters:
Throws:

\OC\User\LoginException

Throws:

\OC\Authentication\Exceptions\PasswordLoginForbiddenException

Throws:

\OC\User\LoginException

Throws:

\OC\Authentication\Exceptions\PasswordLoginForbiddenException

Returns:

bool

protected OC\User\Session::supportsCookies($request)
Source:lib/private/User/Session.php#490
protected OC\User\Session::isTwoFactorEnforced($username)
Source:lib/private/User/Session.php#502
public OC\User\Session::isTokenPassword($password)
Check if the given ‘password’ is actually a device token
Source:

lib/private/User/Session.php#530

Parameters:
  • $password (string)
Returns:

bool

Throws:

\OC\Authentication\Exceptions\ExpiredTokenException

protected OC\User\Session::prepareUserLogin($firstTimeLogin, $refreshCsrfToken=true)
Source:lib/private/User/Session.php#545
public OC\User\Session::tryBasicAuthLogin($request, $throttler)
Tries to login the user with HTTP Basic Authentication
Source:

lib/private/User/Session.php#581

Parameters:
Returns:

bool if the login was successful

public OC\User\Session::createSessionToken($request, $uid, $loginName, $password=null, $remember=\OC\Authentication\Token\IToken::DO_NOT_REMEMBER)
Create a new session token for the given user credentials
Source:

lib/private/User/Session.php#680

Parameters:
  • $request (OCP\IRequest)
  • $uid (string) user UID
  • $loginName (string) login name
  • $password (string)
  • $remember (int)
Returns:

bool

public OC\User\Session::tryTokenLogin($request)
Tries to login the user with auth token header
Source:

lib/private/User/Session.php#817

Parameters:
Returns:

bool

public OC\User\Session::loginWithCookie($uid, $currentToken, $oldSessionId)
perform login using the magic cookie (remember login)
Source:

lib/private/User/Session.php#861

Parameters:
  • $uid (string) the username
  • $currentToken (string)
  • $oldSessionId (string)
Returns:

bool

public OC\User\Session::createRememberMeToken($user)
Source:

lib/private/User/Session.php#912

Parameters:
public OC\User\Session::logout()
logout the user from the session
Source:lib/private/User/Session.php#921
public OC\User\Session::setMagicInCookie($username, $token)
Set cookie value to use in next page load
Source:

lib/private/User/Session.php#944

Parameters:
  • $username (string) username to be set
  • $token (string)
public OC\User\Session::unsetMagicInCookie()
Remove cookie for “remember username”
Source:lib/private/User/Session.php#991
public OC\User\Session::updateSessionTokenPassword($password)
Update password of the browser session token if there is one
Source:

lib/private/User/Session.php#1013

Parameters:
  • $password (string)
public OC\User\Session::updateTokens($uid, $password)
Source:lib/private/User/Session.php#1025