Completed
Pull Request — master (#13)
by Eugene
11:27
created

getAzineHybridAuthService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Azine\HybridAuthBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Symfony\Component\HttpFoundation\ParameterBag;
7
use Symfony\Component\HttpFoundation\RedirectResponse;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use Hybridauth\HttpClient\Util;
11
12
class HybridEndPointController extends Controller
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...e\Controller\Controller has been deprecated with message: since Symfony 4.2, use {@see AbstractController} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
13
{
14
    private $initDone = false;
15
    /**
16
     * @var \Hybrid_Auth
17
     */
18
    private $hybridAuth;
19
20
    /**
21
     * @var ParameterBag
22
     */
23
    private $requestQuery;
24
25
    /**
26
     * Process the current request.
27
     *
28
     * $request - The current request parameters. Leave as NULL to default to use $_REQUEST.
29
     *
30
     * @param Request $request
31
     *
32
     * @return RedirectResponse|Response
33
     */
34
    public function processAction(Request $request)
35
    {
36
//         //Get the request Vars
37
//        $this->requestQuery = $request->query;
38
//
39
//        // init the hybridAuth instance
40
//        $provider = trim(strip_tags($this->requestQuery->get('hauth_start')));
41
        $provider = 'linkedin';
42
        $cookieName = $this->getAzineHybridAuthService()->getCookieName($provider);
43
44
45
        $adapter = $this->getAzineHybridAuthService()->getInstance($request->cookies->get($cookieName), $provider);
46
47
        try {
48
            $adapter->authenticate();
49
            $this->getAzineHybridAuthService()->storeHybridAuthSessionData($request, $provider, json_encode($adapter->getAccessToken()));
50
        } catch (\Exception $e) {
51
            throw new \Exception("Unable to create adapter for provider '$provider'. Is it configured properly?", $e->getCode(), $e);
52
        }
53
54
        $response = new RedirectResponse($this->generateUrl('user_edit'));
55
56
        return $response;
57
    }
58
59
    /**
60
     * @return AzineHybridAuth
61
     */
62
    private function getAzineHybridAuthService()
63
    {
64
        return $this->get('azine_hybrid_auth_service');
65
    }
66
}
67