Code Duplication    Length = 17-17 lines in 2 locations

src/Auth/OAuth2/GigyaCodeGrant.php 1 location

@@ 38-54 (lines=17) @@
35
     */
36
    public function getToken()
37
    {
38
        if (is_null($this->token)) {
39
            $response = $this->gigya->socialize()->getToken([
40
                'authorization_code' => $this->code,
41
                'redirect_uri'       => $this->redirectUri,
42
                'grant_type'         => 'code',
43
            ], ['auth' => 'none']);
44
            if ($response->getErrorCode() == ErrorCode::OK) {
45
                $data = $response->getData();
46
                $token = $data->get('access_token');
47
                $expiresIn = $data->get('expires_in', null);
48
                $expires = null;
49
                if (!is_null($expiresIn)) {
50
                    $expires = (new DateTime())->add(new DateInterval(sprintf('PT%dS', $expiresIn)));
51
                }
52
                $this->token = new AccessToken($token, $expires);
53
            }
54
        }
55
56
        return $this->token;
57
    }

src/Auth/OAuth2/GigyaGrant.php 1 location

@@ 60-76 (lines=17) @@
57
            $this->token = null;
58
        }
59
60
        if (is_null($this->token)) {
61
            $response = $this->gigya->socialize()->getToken([
62
                'client_id'     => $this->userKey ?: $this->apiKey,
63
                'client_secret' => $this->secret,
64
                'grant_type'    => 'none',
65
            ], ['auth' => 'none']);
66
            if ($response->getErrorCode() == ErrorCode::OK) {
67
                $data = $response->getData();
68
                $token = $data->get('access_token');
69
                $expiresIn = $data->get('expires_in', null);
70
                $expires = null;
71
                if (!is_null($expiresIn)) {
72
                    $expires = (new DateTime())->add(new DateInterval(sprintf('PT%dS', $expiresIn)));
73
                }
74
                $this->token = new AccessToken($token, $expires);
75
            }
76
        }
77
78
        return $this->token;
79
    }