If you work in a macro service structure or if you need a very light library to send and receive reposts in a simple service or application, this library will greatly help you.
Currently, it is only implemented to receive tokens from https://www.keycloak.org/, but you can complete it The best usage example is shown in this chart so that you can do the "Request To Service With Token" step with this library.
composer require pickmap/service-request
Define the following variables in your .env file
KEYCLOAK_CLIENT_ID=client-id
KEYCLOAK_CLIENT_SECRET=keycloak-secret-key
KEYCLOAK_USERNAME=usernameOrEmail
KEYCLOAK_PASSWORD=password
KEYCLOAK_LOGIN_URL='https://...openid-connect/token?grant_type=password'
In any class you want to be equipped to send a request like a model or controller, do the following
class sample {
use ServiceRequest;
public function aMethod()
{
self::requestPost('https:://service.com/list');
}
}
You can access these methods separately
//If $refreshToken is equal to true, the token will be refreshed regardless of the cache
self::getToken($refreshToken);
self::requestToKeyCloak();
/*
Authorization is set in all tokens, but with this method, it is overwritten by the third parameter of post and get methods.
*/
self::HeadersProcess($newHeader);
self::requestPost(string $url,array $data = [],$headers = []);
self::requestGet(string $url,array $data = [],$headers = []);