Descrizione...
Dopo aver importato tutto e predisposto un index.php con Slim Framework è sufficente inizializzare un nuovo oggetto OAuth2, aggiungere i GrantType necessari e chiamare la funzione api che genererà i vari endpoint.
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Routing\RouteCollectorProxy as RouteCollectorProxy;
use Slim\Exception\HttpNotFoundException as HttpNotFoundException;
use Slim\Factory\AppFactory;
use \ottimis\phplibs\OAuth2;
$app = AppFactory::create();
$oauth = new OAuth2();
$oauth->addGrantType($oauth::CLIENT_CREDENTIAL);
$oauth->api($app);
Tutti gli endpoint sono nel gruppo /oauth2
Un esempio di chiamata authorize è il seguente:
http://localhost/oauth2/authorize?response_type=code&client_id=testclient&state=xyz
Questa chiamata restituirà al return uri il code necessario per la richiesta del token che verrà effettuata con una post:
curl -u testclient:testpass http://localhost/oauth2/token -d 'grant_type=authorization_code&code=YOUR_CODE'
Una volta avuto il token potrà essere chiamato l'endpoint per la verifica del token e dello scope:
curl http://localhost/oauth2/verify -d 'access_token=YOUR_TOKEN'
- OAuth 2.0 Server PHP by bshaffer - OAuth 2 library
- Slim Framework 4 - Api libs
Creare le tabelle necessarie alla libreria con la seguente query SQL ed importare la libreria con composer
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for logs
-- ----------------------------
DROP TABLE IF EXISTS `logs`;
CREATE TABLE `logs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`type` int(11) DEFAULT NULL,
`stacktrace` text,
`note` text,
`code` varchar(10) DEFAULT NULL,
`datetime` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5397 DEFAULT CHARSET=latin1;
SET FOREIGN_KEY_CHECKS = 1;
<--------------------log_types------------------------------>
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for log_types
-- ----------------------------
DROP TABLE IF EXISTS `log_types`;
CREATE TABLE `log_types` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`log_type` varchar(15) DEFAULT NULL,
`color` varchar(7) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
-- ----------------------------
-- Records of log_types
-- ----------------------------
BEGIN;
INSERT INTO `log_types` VALUES (1, 'Log', '#259d00');
INSERT INTO `log_types` VALUES (2, 'Warning', '#d8a00d');
INSERT INTO `log_types` VALUES (3, 'Error', '#d81304');
COMMIT;
SET FOREIGN_KEY_CHECKS = 1;
use \ottimis\phplibs\OAuth2;
- Ottimis Group