/** * Run the command. */ public function handle() { $client = new Client(['key' => env('OAUTH2_CLIENT_ID'), 'name' => env('OAUTH2_CLIENT_NAME')]); // We need to manually generate the id for the client. $client->setId(ShortId::create()->generate()); // The secret is guarded, so set it manually here. $client->setAttribute('secret', env('OAUTH2_CLIENT_SECRET')); if ($client->save()) { $this->info('Client created.'); } else { $this->error('Could not save client'); } }
/** * @inheritdoc */ public function getBySession(SessionEntity $entity) { $client = Client::findBySessionId($entity->getId()); if ($client === null) { throw new ClientNotFound(); } return $this->createEntity($client); }
/** * @inheritdoc */ public function create($ownerType, $ownerId, $clientId, $clientRedirectUri = null) { $client = Client::findByKey($clientId); if ($client === null) { throw new ClientNotFound(); } $session = new Session(['clientId' => $client->getKey(), 'ownerType' => $ownerType, 'ownerId' => $ownerId, 'clientRedirectUri' => $clientRedirectUri]); $session->setId(ShortId::create()->generate()); $session->save(); return $session->getKey(); }