/**
  * @param \Illuminate\Database\Eloquent\Model|int|string $modelOrId
  *
  * @return \Illuminate\Database\Eloquent\Model
  *
  * @throws \Spatie\Activitylog\Exceptions\CouldNotLogActivity
  */
 protected function normalizeCauser($modelOrId) : Model
 {
     if ($modelOrId instanceof Model) {
         return $modelOrId;
     }
     if ($model = $this->auth->getProvider()->retrieveById($modelOrId)) {
         return $model;
     }
     throw CouldNotLogActivity::couldNotDetermineUser($modelOrId);
 }
 private function resolveUser(Guard $guard)
 {
     // if we're logging in using remember token
     // then we must resolve user „manually”
     // to prevent csrf token regeneration
     $usingSession = $guard instanceof SessionGuard;
     $recaller = $usingSession ? $guard->getRequest()->cookies->get($guard->getRecallerName()) : null;
     if ($usingSession && !is_null($recaller)) {
         list($id, $token) = explode('|', $recaller);
         return $guard->getProvider()->retrieveByToken($id, $token);
     } else {
         return $guard->user();
     }
 }
 /**
  * Returns the authenticatable user instance.
  *
  * @param string $key
  * @param string $username
  *
  * @return \Illuminate\Contracts\Auth\Authenticatable|null
  */
 protected function retrieveAuthenticatedUser($key, $username)
 {
     $provider = $this->auth->getProvider();
     try {
         // Find the user in AD.
         $user = $this->newAdldapUserQuery()->where([$key => $username])->firstOrFail();
         if ($provider instanceof NoDatabaseUserProvider) {
             $this->handleAuthenticatedUser($user);
             return $user;
         } elseif ($provider instanceof DatabaseUserProvider) {
             // Retrieve the Eloquent user model from our AD user instance.
             // We'll assign the user a random password since we don't
             // have access to it through SSO auth.
             $model = $this->getModelFromAdldap($user, str_random());
             // Save model in case of changes.
             $model->save();
             $this->handleAuthenticatedUser($user, $model);
             return $model;
         }
     } catch (ModelNotFoundException $e) {
         //
     }
 }
 /**
  * Returns a new auth model instance.
  *
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function createModel()
 {
     $model = $this->auth->getProvider()->getModel();
     return new $model();
 }