Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applied fixes from StyleCI #651

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions examples/relational/Model/Users.php
Expand Up @@ -19,7 +19,5 @@ public function get($username = null)
if (count($result) > 0) {
return $result;
}

return;
}
}
16 changes: 7 additions & 9 deletions examples/relational/Storage/AccessTokenStorage.php
Expand Up @@ -26,8 +26,6 @@ public function get($token)

return $token;
}

return;
}

/**
Expand All @@ -46,8 +44,8 @@ public function getScopes(AccessTokenEntity $token)
if (count($result) > 0) {
foreach ($result as $row) {
$scope = (new ScopeEntity($this->server))->hydrate([
'id' => $row['id'],
'description' => $row['description'],
'id' => $row['id'],
'description' => $row['description'],
]);
$response[] = $scope;
}
Expand All @@ -63,9 +61,9 @@ public function create($token, $expireTime, $sessionId)
{
Capsule::table('oauth_access_tokens')
->insert([
'access_token' => $token,
'session_id' => $sessionId,
'expire_time' => $expireTime,
'access_token' => $token,
'session_id' => $sessionId,
'expire_time' => $expireTime,
]);
}

Expand All @@ -76,8 +74,8 @@ public function associateScope(AccessTokenEntity $token, ScopeEntity $scope)
{
Capsule::table('oauth_access_token_scopes')
->insert([
'access_token' => $token->getId(),
'scope' => $scope->getId(),
'access_token' => $token->getId(),
'scope' => $scope->getId(),
]);
}

Expand Down
18 changes: 8 additions & 10 deletions examples/relational/Storage/AuthCodeStorage.php
Expand Up @@ -28,18 +28,16 @@ public function get($code)

return $token;
}

return;
}

public function create($token, $expireTime, $sessionId, $redirectUri)
{
Capsule::table('oauth_auth_codes')
->insert([
'auth_code' => $token,
'client_redirect_uri' => $redirectUri,
'session_id' => $sessionId,
'expire_time' => $expireTime,
'auth_code' => $token,
'client_redirect_uri' => $redirectUri,
'session_id' => $sessionId,
'expire_time' => $expireTime,
]);
}

Expand All @@ -59,8 +57,8 @@ public function getScopes(AuthCodeEntity $token)
if (count($result) > 0) {
foreach ($result as $row) {
$scope = (new ScopeEntity($this->server))->hydrate([
'id' => $row['id'],
'description' => $row['description'],
'id' => $row['id'],
'description' => $row['description'],
]);
$response[] = $scope;
}
Expand All @@ -76,8 +74,8 @@ public function associateScope(AuthCodeEntity $token, ScopeEntity $scope)
{
Capsule::table('oauth_auth_code_scopes')
->insert([
'auth_code' => $token->getId(),
'scope' => $scope->getId(),
'auth_code' => $token->getId(),
'scope' => $scope->getId(),
]);
}

Expand Down
12 changes: 4 additions & 8 deletions examples/relational/Storage/ClientStorage.php
Expand Up @@ -34,14 +34,12 @@ public function get($clientId, $clientSecret = null, $redirectUri = null, $grant
if (count($result) === 1) {
$client = new ClientEntity($this->server);
$client->hydrate([
'id' => $result[0]['id'],
'name' => $result[0]['name'],
'id' => $result[0]['id'],
'name' => $result[0]['name'],
]);

return $client;
}

return;
}

/**
Expand All @@ -58,13 +56,11 @@ public function getBySession(SessionEntity $session)
if (count($result) === 1) {
$client = new ClientEntity($this->server);
$client->hydrate([
'id' => $result[0]['id'],
'name' => $result[0]['name'],
'id' => $result[0]['id'],
'name' => $result[0]['name'],
]);

return $client;
}

return;
}
}
8 changes: 3 additions & 5 deletions examples/relational/Storage/RefreshTokenStorage.php
Expand Up @@ -26,8 +26,6 @@ public function get($token)

return $token;
}

return;
}

/**
Expand All @@ -37,9 +35,9 @@ public function create($token, $expireTime, $accessToken)
{
Capsule::table('oauth_refresh_tokens')
->insert([
'refresh_token' => $token,
'access_token' => $accessToken,
'expire_time' => $expireTime,
'refresh_token' => $token,
'access_token' => $accessToken,
'expire_time' => $expireTime,
]);
}

Expand Down
4 changes: 2 additions & 2 deletions examples/relational/Storage/ScopeStorage.php
Expand Up @@ -23,8 +23,8 @@ public function get($scope, $grantType = null, $clientId = null)
}

return (new ScopeEntity($this->server))->hydrate([
'id' => $result[0]['id'],
'description' => $result[0]['description'],
'id' => $result[0]['id'],
'description' => $result[0]['description'],
]);
}
}
18 changes: 7 additions & 11 deletions examples/relational/Storage/SessionStorage.php
Expand Up @@ -30,8 +30,6 @@ public function getByAccessToken(AccessTokenEntity $accessToken)

return $session;
}

return;
}

/**
Expand All @@ -52,8 +50,6 @@ public function getByAuthCode(AuthCodeEntity $authCode)

return $session;
}

return;
}

/**
Expand All @@ -72,8 +68,8 @@ public function getScopes(SessionEntity $session)

foreach ($result as $scope) {
$scopes[] = (new ScopeEntity($this->server))->hydrate([
'id' => $scope['id'],
'description' => $scope['description'],
'id' => $scope['id'],
'description' => $scope['description'],
]);
}

Expand All @@ -87,9 +83,9 @@ public function create($ownerType, $ownerId, $clientId, $clientRedirectUri = nul
{
$id = Capsule::table('oauth_sessions')
->insertGetId([
'owner_type' => $ownerType,
'owner_id' => $ownerId,
'client_id' => $clientId,
'owner_type' => $ownerType,
'owner_id' => $ownerId,
'client_id' => $clientId,
]);

return $id;
Expand All @@ -102,8 +98,8 @@ public function associateScope(SessionEntity $session, ScopeEntity $scope)
{
Capsule::table('oauth_session_scopes')
->insert([
'session_id' => $session->getId(),
'scope' => $scope->getId(),
'session_id' => $session->getId(),
'scope' => $scope->getId(),
]);
}
}
24 changes: 10 additions & 14 deletions examples/relational/api.php
Expand Up @@ -28,32 +28,29 @@

// GET /tokeninfo
$router->get('/tokeninfo', function (Request $request) use ($server) {

$accessToken = $server->getAccessToken();
$session = $server->getSessionStorage()->getByAccessToken($accessToken);
$token = [
'owner_id' => $session->getOwnerId(),
'owner_type' => $session->getOwnerType(),
'owner_id' => $session->getOwnerId(),
'owner_type' => $session->getOwnerType(),
'access_token' => $accessToken,
'client_id' => $session->getClient()->getId(),
'scopes' => $accessToken->getScopes(),
'client_id' => $session->getClient()->getId(),
'scopes' => $accessToken->getScopes(),
];

return new Response(json_encode($token));

});

// GET /users
$router->get('/users', function (Request $request) use ($server) {

$results = (new Model\Users())->get();

$users = [];

foreach ($results as $result) {
$user = [
'username' => $result['username'],
'name' => $result['name'],
'username' => $result['username'],
'name' => $result['name'],
];

if ($server->getAccessToken()->hasScope('email')) {
Expand All @@ -72,16 +69,15 @@

// GET /users/{username}
$router->get('/users/{username}', function (Request $request, Response $response, array $args) use ($server) {

$result = (new Model\Users())->get($args['username']);

if (count($result) === 0) {
throw new NotFoundException();
}

$user = [
'username' => $result[0]['username'],
'name' => $result[0]['name'],
'username' => $result[0]['username'],
'name' => $result[0]['name'],
];

if ($server->getAccessToken()->hasScope('email')) {
Expand Down Expand Up @@ -112,8 +108,8 @@
$response->setContent(json_encode(['status_code' => $e->getStatusCode(), 'message' => $e->getMessage()]));
} catch (\League\OAuth2\Server\Exception\OAuthException $e) {
$response = new Response(json_encode([
'error' => $e->errorType,
'message' => $e->getMessage(),
'error' => $e->errorType,
'message' => $e->getMessage(),
]), $e->httpStatusCode);

foreach ($e->getHttpHeaders() as $header) {
Expand Down
16 changes: 7 additions & 9 deletions examples/relational/authcode_grant.php
Expand Up @@ -39,8 +39,8 @@
} catch (\Exception $e) {
return new Response(
json_encode([
'error' => $e->errorType,
'message' => $e->getMessage(),
'error' => $e->errorType,
'message' => $e->getMessage(),
]),
$e->httpStatusCode,
$e->getHttpHeaders()
Expand All @@ -60,29 +60,27 @@
$redirectUri = $server->getGrantType('authorization_code')->newAuthorizeRequest('user', 1, $authParams);

$response = new Response('', 200, [
'Location' => $redirectUri
'Location' => $redirectUri,
]);

return $response;
});

$router->post('/access_token', function (Request $request) use ($server) {

try {
$response = $server->issueAccessToken();

return new Response(json_encode($response), 200);
} catch (\Exception $e) {
return new Response(
json_encode([
'error' => $e->errorType,
'message' => $e->getMessage(),
'error' => $e->errorType,
'message' => $e->getMessage(),
]),
$e->httpStatusCode,
$e->getHttpHeaders()
);
}

});

$dispatcher = $router->getDispatcher();
Expand All @@ -99,8 +97,8 @@
$response->setContent(json_encode(['status_code' => $e->getStatusCode(), 'message' => $e->getMessage()]));
} catch (\League\OAuth2\Server\Exception\OAuthException $e) {
$response = new Response(json_encode([
'error' => $e->errorType,
'message' => $e->getMessage(),
'error' => $e->errorType,
'message' => $e->getMessage(),
]), $e->httpStatusCode);

foreach ($e->getHttpHeaders() as $header) {
Expand Down