Get access token from code

@param string $code
@return string|boolean
161862
private function getAccessToken($code)
    {

        $data        = [
            "client_id"     => $this->clientId,
            "client_secret" => $this->clientSecret,
            "code"          => $code
        ];
        $data_string = json_encode($data);

        //This needs to be replaced with Guzzle or something async
        $ch = curl_init('https://github.com/login/oauth/access_token');
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt(
            $ch,
            CURLOPT_HTTPHEADER,
            [
                'Content-Type: application/json',
                'Content-Length: ' . strlen($data_string)
            ]
        );

        $result = curl_exec($ch);
        parse_str($result, $resultArray);

        if (isset($resultArray['access_token'])) {
            return $resultArray['access_token'];
        } else {
            return false;
        }
    }
1154434
public function authenticate($code)
    {
        if (empty($code)) {
            throw new NostoException('Invalid authentication token');
        }

        $request = new HttpRequest();
        $request->setUrl(Nosto::getOAuthBaseUrl() . self::PATH_TOKEN);
        $request->setReplaceParams(
            array(
                '{cid}' => $this->clientId,
                '{sec}' => $this->clientSecret,
                '{uri}' => $this->redirectUrl,
                '{cod}' => $code
            )
        );
        $response = $request->get();
        $result = $response->getJsonResult(true);

        if ($response->getCode() !== 200) {
            throw ExceptionBuilder::fromHttpRequestAndResponse($request, $response);
        }
        if (empty($result['access_token'])) {
            throw new NostoException('No "access_token" returned after authenticating with code');
        }
        if (empty($result['merchant_name'])) {
            throw new NostoException('No "merchant_name" returned after authenticating with code');
        }

        return NostoOAuthToken::create($result);
    }
1332894
public function getAccessPermission($code)
    {
        $queryStr = [
            'appid'      => $this->getAppId(),
            'secret'     => $this->getAppSecret(),
            'code'       => $code,
            'grant_type' => 'authorization_code',
        ];

        $this->apitype = 'sns';
        $this->module  = 'oauth2';
        $res           = $this->_get('access_token', $queryStr);

        return $res;
    }
1155702
public function getUserId($code)
    {
        $apiUrl = 'https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo';

        $result = $this->_curl($apiUrl, [
            'access_token' => $this->getAccessToken(),
            'code' => $code,
        ]);

        return ($result and isset($result['UserId'])) ? $result['UserId'] : null;
    }
287466
public static function getDescription($code)
    {
        if (array_key_exists($code, self::$codes_to_string_map)) {
            return self::$codes_to_string_map[$code];
        } else {
            return false;
        }
    }
955721
public function getAccessToken($code = null) {
        if ($this->debug) { $start = microtime(true); }
        if ($code) {
            // todo get access_token via authorization_code request
            $params['client_id']     = $this->getClientID();
            $params['client_secret'] = $this->getClientSecret();
            $params['redirect_uri']  = $this->getRedirectUri();
            $params['grant_type']    = 'authorization_code';
            $params['scope']         = '';
            $params['state']         = '';
            $params['code']          = $code;
            $access_token = (array) json_decode($this->makeRequest($this->getTokenURL(), $params));
        } else {
            if ($this->accessToken) {
                return $this->accessToken;
            } else {
                $session = $this->getSession();
                // either user session signed, or app signed
                if (isset($session['access_token'])) {
                    $access_token = $session['access_token'];
                } else {
                    // No success! Defaults to
                    $access_token = $this->getClientID();
                }
            }
        }
        if ($this->debug) { $this->timer[__FUNCTION__]['elapsed'][] = microtime(true)-$start; }
        return $access_token;
    }
323176
public function getAuthorizationCode($code)
    {
        $code = $this->getObjectByType('code_table',$code);

        return is_null($code) ? false : $code;
    }
599912
public function getTokenForCode($code, $state)
    {
        if ($state != $_SESSION['oauth2_lockme_state']) {
            unset($_SESSION['oauth2_lockme_state']);
            throw new \Exception("Wrong state");
        }
        unset($_SESSION['oauth2_lockme_state']);

        $this->accessToken = $this->provider->getAccessToken('authorization_code', [
        'code' => $code
    ]);
        return $this->accessToken;
    }
655224
public static function get($code)
  {
    if (array_key_exists($code, self::$translations)) {
      return self::$translations[$code];
    }
    return sprintf('[%s]', $code);
  }
495332
public function requestToken($code)
    {
        $parameters = [
            'client_id' => config('twitch-api.client_id'),
            'client_secret' => config('twitch-api.client_secret'),
            'redirect_uri' => config('twitch-api.redirect_url'),
            'code' => $code,
            'grant_type' => 'authorization_code'
        ];

        try {
            $client = new Client();

            $response = $client->post(config('twitch-api.api_url') . '/kraken/oauth2/token', ['body' => $parameters]);

            $response = $response->json();

            if (isset($response[ 'access_token' ])) {

                return $response[ 'access_token' ];
            }

        } catch (\Exception $e) {

            throw $e;
        }
    }
615123
protected function getAuthCode($code)
    {
        if (null === $code = $this->app['repo.api-oauth-codes']->find($code)) {
            return null;
        }

        return [
            'redirect_uri' => $code->getRedirectUri(),
            'client_id'    => $code->getAccount()->getApplication()->getClientId(),
            'expires'      => $code->getExpires(),
            'account_id'   => $code->getAccount()->getId(),
        ];
    }
1173698
public function authenticate($code)
    {
        if ( $code )
        {
            $this->client->authenticate($code);

            $access_token = $this->client->getAccessToken();

            $this->session->put('googleapi_token', $access_token);

            return true;
        }

        return false;
    }
960803
public static function authentication($code = '')
    {
        if (empty($code)) {
            return false;
        }

        // authorize
        $authorize = self::authorize($code);

        if (!$authorize) {
            return false;
        }

        if (isset($authorize['error'])) {
            return $authorize;
        }

        // return infos
        return self::info($authorize['access_token']);
    }
174508
public function generateToken($code)
    {
        $this->token = $this->provider->getAccessToken('authorization_code', [
            'code' => $code
        ]);

        return $this->token;
    }
1041938
public static function get( $code = 200 )
	{
		if( isset( self::$http_status_codes[$code] ) )
		{
			return( self::$http_status_codes[ $code ] );
		}
		return( false );
	}
689140
public function getToken($code)
	{
		$request = 	new Request('POST', 'token', [], http_build_query([
			'redirect_uri'  => $this->getRedirectUri(),
			'client_id'		=> $this->getClientId(),
			'client_secret' => $this->getClientSecret(),
			'grant_type' 	=> 'authorization_code',
			'code' 			=> $code
		]));

		try {
			$response = $this->getHttpClient()->send($request);
		} catch (\Exception $e) {
			throw new SurveyMonkeyApiException($e->getMessage(), $e->getCode(), $e);
		}

		if (!$response->hasHeader('content-type') || !preg_match('/application\/json/i', $response->getHeader('content-type')[0])) {
			throw new SurveyMonkeyApiException(spritnf('Response expected to be a JSON response. Received %s', $response->getHeader('content-type')[0]));
		}

		return json_decode($response->getBody(), true);
	}
464126
public function getAccessCode($accessCode)
    {
        if (empty($accessCode)) {
            throw new InvalidArgumentException();
        }

        return $this->getRequest([
            self::API_ACCESS_CODE_QUERY,
            ['AccessCode' => $accessCode]
        ]);
    }