public function getHost($id) { $host = Host::where('id', $id)->first(); if ($host != null) { $array = array('success' => true, 'host' => $host); return json_encode($array); } else { $array = array('success' => false, 'message' => 'Host not Found'); return json_encode($array); } }
$authorizationServer = new \League\OAuth2\Server\AuthorizationServer(); $authorizationServer->setSessionStorage($sessionStorage); $authorizationServer->setAccessTokenStorage($accessTokenStorage); $authorizationServer->setClientStorage($clientStorage); $authorizationServer->setScopeStorage($scopeStorage); $authorizationServer->setRefreshTokenStorage($refreshTokenStorage); //$clientCredentials = new \League\OAuth2\Server\Grant\ClientCredentialsGrant(); //$server->addGrantType($clientCredentials); $refreshTokenGrant = new \League\OAuth2\Server\Grant\RefreshTokenGrant(); $authorizationServer->addGrantType($refreshTokenGrant); $resourceServer = new ResourceServer($sessionStorage, $accessTokenStorage, $clientStorage, $scopeStorage, $refreshTokenStorage); $passwordGrant = new \League\OAuth2\Server\Grant\PasswordGrant(); $authorizationServer->addGrantType($passwordGrant); $passwordGrant->setVerifyCredentialsCallback(function ($username, $password) use($app) { // implement logic here to validate a username and password, return an ID if valid, otherwise return false $host = new Host(); $valid = $host->oauth2Login($username, $password); if ($valid !== false) { return $valid; } else { $app->halt(401, 'Unauthorized. The user credentials were incorrect.'); } }); $authorize = function () use($resourceServer) { return function () use($resourceServer) { //401 = Unauthorized //403 = Forbidden $app = \Slim\Slim::getInstance(); try { $authenticated = $resourceServer->isValidRequest(false); if ($authenticated === false) {