/** * View a post. * * @param string $slug * @return View * @throws NotFoundHttpException */ public function getView($slug) { // Get this blog post data $client = ClientMetadata::where('key', '=', 'slug')->where('value', '=', $slug)->first()->client()->first(); //var_dump($client);die; // Check if the blog post exists if (is_null($client)) { // If we ended up in here, it means that // a page or a blog post didn't exist. // So, this means that it is time for // 404 error page. return Client::abort(404); } // Show the page return View::make('site/clients/view_client', compact('client')); }
public function action_userinfo() { try { $this->resource = new League\OAuth2\Server\Resource($this->authserver->getStorage('session')); $this->resource->setRequest(new League\OAuth2\Server\Util\Request($_GET, $_POST, array(), array(), array('HTTP_AUTHORIZATION' => $_ENV['HTTP_AUTHORIZATION']), array('Authorization' => $_ENV['HTTP_AUTHORIZATION']))); //Validate Access Token //Will throw an exception is token is invalid. No need for IF statement $this->resource->isValid(); if ($this->resource->getOwnerType() != 'user') { throw new ModelNotFoundException("Only access tokens representing users can use this endpoint"); } if (!array_key_exists('schema', $this->resource->getRequest()->get()) or $this->resource->getRequest()->get()['schema'] != 'openid') { throw new Exception("The only defined schema is openid"); } $token = $this->resource->getAccessToken(); $client_url = ClientMetadata::where('client_id', $this->resource->getClientId())->where('key', 'website')->first()->value; //dd($client_url); $user = User::where('id', $this->resource->getOwnerId())->first(); //$user = User::findOrFail(10); $scopes = $this->resource->getScopes(); $openid = false; foreach ($scopes as $scope) { if ($scope == 'openid') { $openid = true; break; } } //Clients making UserInfo requests MUST have the openid scope if (!$openid) { throw new League\OAuth2\Server\Exception\ClientException(sprintf($this->authserver->getExceptionMessage('access_denied')), 2); } $response = array(); //dd(json_encode($scopes)); foreach ($scopes as $scope) { if ($scope == 'openid') { $response["sub"] = $user->pid; } if ($scope == 'email') { $response["email"] = $user->email; $response["verified"] = $user->confirmed == 1 ? true : false; } if ($scope == 'profile') { //"name","given_name","family_name","address","city","state","zip","email","verified","phone"], $response["name"] = $user->first_name . ' ' . $user->last_name; $response["given_name"] = $user->first_name; $response["family_name"] = $user->last_name; $response["phone"] = $user->phone; $response["mobile"] = $user->mobile; $response["email"] = $user->email; $response["verified"] = $user->confirmed == 1 ? true : false; $response["address"] = $user->street . ', ' . $user->city . ', ' . strtoupper($user->state) . ' ' . $user->zip; $response["street"] = $user->street; $response["city"] = $user->city; $response["state"] = $user->state; $response["zip"] = $user->zip; $response["role"] = $user->oauth_role($client_url); } } } catch (League\OAuth2\Server\Exception\ClientException $e) { // Throw an exception because there was a problem with the client's request $response = array('error' => $this->authserver->getExceptionType($e->getCode()), 'error_description' => $e->getMessage()); // Set the correct header header($this->authserver->getExceptionHttpHeaders($this->authserver->getExceptionType($e->getCode()))[0]); } catch (ModelNotFoundException $e) { http_response_code(404); $response = array('error' => "Resource owner not found"); } catch (Exception $e) { // Throw an error when a non-library specific exception has been thrown $response = array('error' => 'undefined_error', 'error_description' => $e->getMessage()); } header('Content-type: application/json'); echo json_encode($response); }