public function get($clientId, $clientSecret = null, $redirectUri = null, $grantType = null) { $query = App::where('id', '=', $clientId); if ($clientSecret !== null) { $query->where('secret', '=', $clientSecret); } if ($redirectUri) { $query->where('redirect_uri', '=', $redirectUri); } $result = $query->get(); if (count($result) === 1) { $client = new ClientEntity($this->server); $client->hydrate(['id' => $result[0]['id'], 'name' => $result[0]['name']]); return $client; } return; }
public function create($ownerType, $ownerId, $clientId, $clientRedirectUri = null) { $app = App::where('id', '=', $clientId)->first(); if ($app) { $session = new Session(); $session->owner_type = $ownerType; $session->app_id = $app->id; if ($ownerType == 'client') { $session->owner_id = null; } else { // ($ownerType == 'user') assumed anyway $session->owner_id = $ownerId; } $session->save(); return $session->id; } }
OAuthHelper::needsScopes(['user', 'user:apps']); $body = Tool::getBody(); // $recaptcha = new ReCaptcha(Tool::getConfig()['recaptcha_secret']); // if (!isset($body->recaptcha_response) || // gettype($body->recaptcha_response) != 'string' || // !$recaptcha->verify($body->recaptcha_response) // ->isSuccess()) { // throw new InvalidRecaptcha; // } $user_id = $resourceServer->getAccessToken()->getSession()->getOwnerId(); $user = User::where('id', '=', $user_id)->first(); $app = new App(); if (!isset($body->name) || !App::isValidName($body->name)) { throw new InvalidField('name'); } else { if (App::where('user_id', '=', $user_id)->where('name', '=', $body->name)->first() != null) { throw new UnavailableName('app', $name); } else { $app->name = $body->name; } } if (isset($body->homepage_url)) { if (!App::isValidUrl($body->homepage_url)) { throw new InvalidField('url'); } else { $app->homepage_url = $body->homepage_url; } } if (isset($body->description)) { if (!App::isValidDescription($body->description)) { throw new \API\Exception\InvalidField('description');