I'm using Symfony2 to talk to an API then start a session. I have my OauthCallbackController.php
that finishes the authorization process then starts a sessions and sets some variables. I then want to be able to access those variables from my other controllers, to ensure that I have proper access to the API.
There are so many different (and confusing) ways I've read about in Symfony2 sessions, right now I'm using below:
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\RedirectResponse;
class OauthCallbackController extends Controller
{
public function callbackAction(Request $request)
{
$session = new Session();
$session->start();
// Oauth Code here
$json_response = curl_exec($curl);
$response = json_decode($json_response, true);
$access_token = $response['access_token'];
$instance_url = $response['instance_url'];
$session->set('access_token', $access_token);
$session->set('instance_url', $instance_url);
return new RedirectResponse("rootpage.com");
}
}
This is how I perceive starting a session, but I cannot figure out how to use/access this session in my other controllers. So if anyone can help me with that, or if I'm doing the session creation wrong, please provide feedback.