Authenticate user and get access token from server

@param string $code

@return $this
771301
public function authenticate($code = null)
    {
        if (null === $code) {
            if (isset($_GET['code'])) {
                $code = $_GET['code'];
            }
        }

        $url = 'https://oauth.vk.com/access_token?' . http_build_query(array(
                'client_id' => $this->getClientId(),
                'client_secret' => $this->getClientSecret(),
                'code' => $code,
                'redirect_uri' => $this->getRedirectUri(),
            ));

        $token = $this->curl($url);
        $decodedToken = json_decode($token, true);
        $decodedToken['created'] = time(); // add access token created unix timestamp to array

        $this->setAccessToken($decodedToken);

        return $this;
    }
270471
public function getAccessToken($code = '')
	{
		$dta = array('client_id' => $this->_API['API_KEY'], 'client_secret' => $this->_API['API_SECRET'], 'code' => $code);
		$data = $this->call(['METHOD' => 'POST', 'URL' => 'https://' . $this->_API['SHOP_DOMAIN'] . '/admin/oauth/access_token', 'DATA' => $dta], FALSE);

		return $data->access_token;
	}
220481
public function requestAccessToken($code, $requestType)
    {
        switch ($requestType) {
            case 'pin':
                $grantType = 'pin';
                $type = 'pin';
                break;
            case 'code':
            default:
                $grantType = 'authorization_code';
                $type = 'code';
        }

        try {
            $response = $this->httpClient->post(
                self::ACCESS_TOKEN_ENDPOINT,
                [
                    'client_id' => $this->clientId,
                    'client_secret' => $this->clientSecret,
                    'grant_type' => $grantType,
                    $type => $code,
                ]
            );

            $responseBody = json_decode($response->getBody(), true);
        } catch (\Exception $e) {
            throw new AuthException('Request for access token failed: ' . $e->getMessage(), $e->getCode());
        }

        $responseBody['created_at'] = time();
        $this->setAccessToken($responseBody);

        $this->sign();

        return $responseBody;
    }
844068
private function setStatusHeader($code = 200)
    {
        if (empty(self::$codes[$code])) {
            $code = 200;
        }

        if (!empty($this->response)) {
            $this->response->status($code);
        }

        return $this;
    }
1284477
public function authenticate() {
    $this->getClient()->authenticate($this->getApiToken(), \Github\Client::AUTH_HTTP_TOKEN);
    return $this;
  }
848605
public function get($code)
    {
        $result = $this->getConnection()->table('oauth_auth_codes')
            ->where('oauth_auth_codes.id', $code)
            ->where('oauth_auth_codes.expire_time', '>=', time())
            ->first();

        if (is_null($result)) {
            return;
        }

        return (new AuthCodeEntity($this->getServer()))
            ->setId($result->id)
            ->setRedirectUri($result->redirect_uri)
            ->setExpireTime((int) $result->expire_time);
    }
984391
protected function getTokenUrl($code) {
		return $this->providerOptions['access_token'] . '?client_id=' . $this->client_id . '&client_secret=' . $this->client_secret . '&code=' . $code . '&redirect_uri=' . urlencode($this->getState('redirect_uri'));
	}
588920
public function get_access_token( $code, $client_id, $client_secret ) {
		$contents = $this->get_contents( 'token_url', $this->get_access_token_params( $code, $client_id, $client_secret ) );
		$response = @json_decode( $contents, true );
		if ( empty( $response ) || ! empty( $response['error'] ) ) {
			$this->app->log( 'social response error', [
				'$contents' => $contents,
				'$response' => $response,
			] );

			return false;
		}

		return $response['access_token'];
	}
1133033
public function requestAccessToken($authorizationCode)
    {
        $parameters = [
            'client_id' => $this->getClientId(),
            'client_secret' => $this->getClientSecret(),
            'code' => $authorizationCode,
            'grant_type' => 'authorization_code',
            'redirect_uri' => $this->getRedirectUri(),
        ];

        $response = $this->request->account('POST', '/api/token', $parameters, []);
        $response = $response['body'];

        if (isset($response->refresh_token) && isset($response->access_token)) {
            $this->refreshToken = $response->refresh_token;
            $this->accessToken = $response->access_token;
            $this->expirationTime = time() + $response->expires_in;
            $this->scope = isset($response->scope) ? $response->scope : $this->scope;

            return true;
        }

        return false;
    }
1043591
public function getAuthorizationCode($code)
    {
        $code = $this->collection('code_table')->findOne(array(
            'authorization_code' => $code
        ));
        return is_null($code) ? false : $code;
    }
192627
public function authenticate($provider, $code=False)
    {
        if($code){
            return $this->handleProviderCallback($provider);
        }

        return $this->redirectToProvider($provider);
    }
373111
public function getAuth($code)
    {
        $result = $this->_curl(
            'https://api.weixin.qq.com/sns/oauth2/access_token',
            [
                'appid' => $this->getConfig('appid'),
                'secret' => $this->getConfig('secret'),
                'code' => $code,
                'grant_type' => 'authorization_code',
            ]
        );

        if ($result) {
            return [
                'access_token' => $result['access_token'],
                'openid' => $result['openid'],
            ];
        }

        return false;
    }
1163523
public function setStatusCode($code)
    {
        $this->headerBag->setStatusCode($code);
        $this->statusCode = $code;

        return $this;
    }
1260224
public function getOAuthToken($code, $token = false)
    {
        $apiData = array(
            'grant_type' => 'authorization_code',
            'client_id' => $this->getApiKey(),
            'client_secret' => $this->getApiSecret(),
            'redirect_uri' => $this->getApiCallback(),
            'code' => $code
        );

        $result = $this->_makeOAuthCall($apiData);

        return !$token ? $result : $result->access_token;
    }
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']);
    }
1300577
public function getOAuth2AccessToken($code) {
        $url = sprintf(self::OAUTH2_ACCESS_TOKEN_URL, $this->appId, $this->appSecret, $code);
        $client = $this->getHttpClient();
        $client->setUrl($url);
        $client->setHeaderArray(['Content-Type: application/json']);

        if (!$client->exec()) {
            throw new Exception("call get oauth2 access token fail");
        }

        $result = json_decode($client->getResponse(), true);
        if (!(isset($result['access_token']) && isset($result['openid']))) {
            throw new Exception("call get oauth2 access token fail url({$url}) access_token or openid is not exists, response:" . $client->getResponse());
        }

        return ['accessToken' => trim($result['access_token']), 'openId' => trim($result['openid'])];
    }
1303390
public function getAccess($code, $refreshToken = false)
    {
        //argument 1 must be a string
        Argument::i()->test(1, 'string');

        //populate fields
        $query = array(
            'client_id'         => $this->client,
            'client_secret'     => $this->secret,
            'redirect_uri'  => $this->redirect,
            'grant_type'    => $this->grantType);

        return $this->generateAccess($query, $code, $refreshToken);
    }