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; } }
} else { if ($user->apps()->where('name', '=', $body->name)->first()) { throw new UnavailableName('App', $body->name); } $user_app->name = $body->name; } } if (isset($body->homepage_url)) { if (gettype($body->homepage_url) != 'string' || !App::isValidUrl($body->homepage_url)) { throw new InvalidField('homepage_url'); } else { $user_app->homepage_url = $body->homepage_url; } } if (isset($body->description)) { if (gettype($body->description) != 'string' || !App::isValidDescription($body->description)) { throw new InvalidField('description'); } else { $user_app->description = $body->description; } } $user_app->save(); Tool::endWithJson($user_app); }); $user_delete_app = Tool::makeEndpoint(function ($id) use($app, $resourceServer) { OAuthHelper::needsScopes(['user', 'user:apps']); $body = Tool::getBody(); $user_id = $resourceServer->getAccessToken()->getSession()->getOwnerId(); $user = User::where('id', '=', $user_id)->first(); $user_app = $user->apps()->find($id); if ($user_app) {