Commit 0341d46d authored by pcallejo's avatar pcallejo Committed by adacruz
Browse files

Resolve "Route to get M2M Token and Auth0 Client infos"

parent f94840db
###> symfony/framework-bundle ###
/.env
/public/bundles/
/var/
/vendor/
/.idea
/cc
docker/php/composer_cache
###< symfony/framework-bundle ###
###> symfony/phpunit-bridge ###
.phpunit
/phpunit.xml
###< symfony/phpunit-bridge ###
###> symfony/web-server-bundle ###
/.web-server-pid
###< symfony/web-server-bundle ###
###> symfony/webpack-encore-bundle ###
/node_modules/
/public/build/
npm-debug.log
yarn-error.log
###< symfony/webpack-encore-bundle ###
......@@ -10,8 +10,8 @@ namespace Aboutgoods\KonnectBundle;
use Aboutgoods\KonnectBundle\Event\LoginEvent;
use Aboutgoods\KonnectBundle\Event\LogoutEvent;
use net\aboutgoods\konnect\Konnect;
use net\aboutgoods\konnect\model\response\User;
use net\aboutgoods\konnect\model\response\Authorization;
use net\aboutgoods\konnect\model\response\User;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class Client
......
<?php
namespace Aboutgoods\KonnectBundle\Controller;
use Aboutgoods\KonnectBundle\Services\KonnectApi;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Annotation\Route;
/**
* CompanyController gets the auth0 Client info to use with different services (API Console, etc)
* The first route gets the M2M Client Token (Access token)
* The second route gets the auth0ClintId and ath0ClientSecret
*/
class CompanyController extends Controller
{
/**
* @Route("/company/m2m")
* @param KonnectApi $konnectApi
* @return
*/
public function getCompanyM2MTokenAction(KonnectApi $konnectApi)
{
$companyId = $this->getUser()->getCompany();
$config = $this->get('konnect.client')->getConfiguration();
return $this->json($konnectApi->getCompanyM2MToken($companyId, $config));
}
/**
* @Route("/company/info")
* @param KonnectApi $konnectApi
* @return
*/
public function getCompanyAuth0Infos(KonnectApi $konnectApi)
{
$companyId = $this->getUser()->getCompany();
$config = $this->get('konnect.client')->getConfiguration();
return $this->json($konnectApi->getCompanyAuth0Infos($companyId, $config));
}
}
\ No newline at end of file
......@@ -12,6 +12,12 @@ services:
public: true
Aboutgoods\KonnectBundle\Controller\LoginController:
alias: konnect.login.controller
konnect.company.controller:
class: Aboutgoods\KonnectBundle\Controller\CompanyController
public: true
Aboutgoods\KonnectBundle\Controller\CompanyController:
alias: konnect.company.controller
##
# PROVIDER
##
......
......@@ -18,4 +18,30 @@ class KonnectApi
]);
return json_decode($response->getBody()->getContents(),true);
}
public function getCompanyM2MToken($companyId, $config) {
$client = new Client();
$config = $config['authentication'];
$response = $client->get($config['url'] . "/api/company/$companyId/m2m", [
'auth' => [
$config['token'],
$config['secret']
]
]);
return json_decode($response->getBody()->getContents(),true);
}
public function getCompanyAuth0Infos($companyId, $config) {
$client = new Client();
$config = $config['authentication'];
$response = $client->get($config['url'] . "/api/company/$companyId/info", [
'auth' => [
$config['token'],
$config['secret']
]
]);
return json_decode($response->getBody()->getContents(),true);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment