/** * Get a code from storage. * * @param string $code * @return \Dingo\OAuth2\Entity\AuthorizationCode */ public function get($code) { if (isset($this->cache[$code])) { return $this->cache[$code]; } $query = $this->connection->prepare(sprintf('SELECT * FROM %1$s WHERE code = :code', $this->tables['authorization_codes'])); if (!$query->execute([':code' => $code]) or !($code = $query->fetch())) { return false; } $code = new AuthorizationCodeEntity($code['code'], $code['client_id'], $code['user_id'], $code['redirect_uri'], strtotime($code['expires'])); // Now that the code has been fetched and the entity created we'll also fetch // the associated scopes of the code. $query = $this->connection->prepare(sprintf('SELECT %1$s.* FROM %1$s LEFT JOIN %2$s ON %1$s.scope = %2$s.scope WHERE %2$s.code = :code', $this->tables['scopes'], $this->tables['authorization_code_scopes'])); if ($query->execute([':code' => $code->getCode()])) { $scopes = []; foreach ($query->fetchAll() as $scope) { $scopes[$scope['scope']] = new ScopeEntity($scope['scope'], $scope['name'], $scope['description']); } $code->attachScopes($scopes); } return $this->cache[$code->getCode()] = $code; }
/** * Get a code from storage. * * @param string $code * @return \Dingo\OAuth2\Entity\AuthorizationCode */ public function get($code) { if (!($value = $this->getValue($code, $this->tables['authorization_codes']))) { return false; } $code = new AuthorizationCodeEntity($code, $value['client_id'], $value['user_id'], $value['redirect_uri'], $value['expires']); $scopes = []; // Get the authorization code scopes set and spin through each scope // on the set and create a scope entity. foreach ($this->getSet($code->getCode(), $this->tables['authorization_code_scopes']) as $scope) { $scopes[$scope['scope']] = new ScopeEntity($scope['scope'], $scope['name'], $scope['description']); } $code->attachScopes($scopes); return $code; }
/** * Get a code from storage. * * @param string $code * @return \Microweber\OAuth2\Entity\AuthorizationCode|bool */ public function get($code) { if (isset($this->cache[$code])) { return $this->cache[$code]; } $query = $this->connection->table($this->tables['authorization_codes'])->where('code', $code); if (!($code = $query->first())) { return false; } $code = new AuthorizationCodeEntity($code->code, $code->client_id, $code->user_id, $code->redirect_uri, strtotime($code->expires)); // Now that the code has been fetched and the entity created we'll also fetch // the associated scopes of the code. $query = $this->connection->table($this->tables['scopes'])->select($this->tables['scopes'] . '.*')->leftJoin($this->tables['authorization_code_scopes'], $this->tables['scopes'] . '.scope', '=', $this->tables['authorization_code_scopes'] . '.scope')->where($this->tables['authorization_code_scopes'] . '.code', $code->getCode()); $scopes = []; foreach ($query->get() as $scope) { $scopes[$scope->scope] = new ScopeEntity($scope->scope, $scope->name, $scope->description); } $code->attachScopes($scopes); return $this->cache[$code->getCode()] = $code; }