<commit_before><?php

namespace SigninBundle\Controller;

use SigninBundle\Resources\GenerateCacheKey;
use AppBundle\Utils\RedisCache;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class DefaultController extends Controller
{
    use GenerateCacheKey;

    /**
     * @param \Symfony\Component\HttpFoundation\Request $request
     * @param string                                    $originator
     *
     * @Route("/callback/{originator}", name="signin-callback", requirements={"originator": "[g]{1}"})
     *
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     */
    public function callback(Request $request, $originator)
    {
        if ($originator == 'g') {
            // Process Google Signin
            $code = $request->get('code');
            if ($request->get('code')) {
                /** @var \SigninBundle\Model\Auth\Google $google */
                $google = $this->get('signin.google');

                /** @var \Google_Client $client */
                $client = $google->getClient();

                $token = $client->fetchAccessTokenWithAuthCode($code);
                $client->setAccessToken($token);

                $tokenData = $client->verifyIdToken();

                // Start Validation
                // @link https://developers.google.com/identity/sign-in/web/backend-auth
                if ($tokenData['aud'] !== $client->getClientId()) {
                    throw new Exception($tokenData['aud'] . ' does not match ', $client->getClientId());
                } else {
                    if (!in_array($tokenData['iss'], [
                        'accounts.google.com',
                        'https://accounts.google.com',
                    ])
                    ) {
                        throw new Exception($tokenData['iss'] . ' is not one of accounts.google.com, https://accounts.google.com');
                    } else {
                        if (date('U') > $tokenData['exp']) {
                            throw new Exception('current date ' . date('U') . ' is greater than expiry: ' . $tokenData['exp']);
                        } else {
                            // Valid Request - Save to session and redirect back to this page
                            /** @var \Google_Service_Oauth2_Userinfoplus $googleUserData */
                            $googleUserData = $google->getLoggedInUser();

                            /** @var \AppBundle\Utils\Api\Redis $api */
                            $api = $this->get('app.api.redis');

                            $sessId = uniqid('sess', true);
                            $redisCacheKey = $this->createCacheKey($request, $sessId);

                            if (!$api->read($redisCacheKey)['result']) {
                                $api->create(
                                    (array)$googleUserData->toSimpleObject() +<commit_msg>Fixed issue with consistant JWT failures<commit_after><?php

namespace SigninBundle\Controller;

use SigninBundle\Resources\GenerateCacheKey;
use AppBundle\Utils\RedisCache;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class DefaultController extends Controller
{
    use GenerateCacheKey;

    /**
     * @param \Symfony\Component\HttpFoundation\Request $request
     * @param string                                    $originator
     *
     * @Route("/callback/{originator}", name="signin-callback", requirements={"originator": "[g]{1}"})
     *
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     */
    public function callback(Request $request, $originator)
    {
        if ($originator == 'g') {
            // Process Google Signin
            $code = $request->get('code');
            if ($code) {
                /** @var \SigninBundle\Model\Auth\Google $google */
                $google = $this->get('signin.google');

                /** @var \Google_Client $client */
                $client = $google->getClient();

                $token = $client->fetchAccessTokenWithAuthCode($code);
                $client->setAccessToken($token);

                $tokenData = $client->verifyIdToken($token['id_token']);

                // Start Validation
                // @link https://developers.google.com/identity/sign-in/web/backend-auth
                if ($tokenData['aud'] !== $client->getClientId()) {
                    throw new Exception($tokenData['aud'] . ' does not match ', $client->getClientId());
                } else {
                    if (!in_array($tokenData['iss'], [
                        'accounts.google.com',
                        'https://accounts.google.com',
                    ])
                    ) {
                        throw new Exception($tokenData['iss'] . ' is not one of accounts.google.com, https://accounts.google.com');
                    } else {
                        if (date('U') > $tokenData['exp']) {
                            throw new Exception('current date ' . date('U') . ' is greater than expiry: ' . $tokenData['exp']);
                        } else {
                            // Valid Request - Save to session and redirect back to this page
                            /** @var \Google_Service_Oauth2_Userinfoplus $googleUserData */
                            $googleUserData = $google->getLoggedInUser();

                            /** @var \AppBundle\Utils\Api\Redis $api */
                            $api = $this->get('app.api.redis');

                            $sessId = uniqid('sess', true);
                            $redisCacheKey = $this->createCacheKey($request, $sessId);

                            if (!$api->read($redisCacheKey)['result']) {
                                $api->create(
                                    (array)$googleUserData->toSimpleObject() +
{'fraction_non_alphanumeric': 0.13123486682808716, 'fraction_numerical': 0.000645682001614205, 'mean_word_length': 1.6558079725675097, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 34, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5389243', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1509, 'n_words': 283}