Make an API with access_token
775721
def call(path, http_method: :get, body: {}, header: {})
      # add bearer token to header
      header[:authorization] = "Bearer #{access_token}"
      return ShakeTheCounter::API.call(path, http_method: http_method, body: body, header: header)
    end
1060482
def extract_access_token(request):
    
    auth_header = request.META.get('HTTP_AUTHORIZATION', '')

    if re.compile('^[Bb]earer\s{1}.+$').match(auth_header):
        access_token = auth_header.split()[1]
    else:
        access_token = request.GET.get('access_token', '')

    return access_token
113057
async def _request(
            self,
            method: str,
            url: str,
            *,
            access_token: str = None,
            access_token_expiration: datetime = None,
            headers: dict = None,
            params: dict = None,
            json: dict = None,
            ssl: bool = True) -> dict:
        """"""
        if (access_token_expiration
                and datetime.now() >= access_token_expiration):
            raise TokenExpiredError('Long-lived access token has expired')

        if not headers:
            headers = {}
        headers.update({'Content-Type': 'application/json'})

        if not params:
            params = {}
        if access_token:
            params.update({'access_token': access_token})

        try:
            async with async_timeout.timeout(self.request_timeout):
                async with self._websession.request(
                        method, url, headers=headers, params=params, json=json,
                        ssl=ssl) as resp:
                    resp.raise_for_status()
                    data = await resp.json(content_type=None)
                    _raise_for_remote_status(url, data)
        except ClientError as err:
            raise RequestError(
                'Error requesting data from {0}: {1}'.format(url, err))
        except asyncio.TimeoutError:
            raise RequestError('Timeout during request: {0}'.format(url))

        return data
164938
def request_token(params)
    if scope = Util.arglist(params.delete(:scope))
      params[:scope] = Util.strlist(scope)
    end
    headers = {'content-type' => FORM_UTF8, 'accept' => JSON_UTF8,
        'authorization' => Http.basic_auth(@client_id, @client_secret) }
    reply = json_parse_reply(@key_style, *request(@token_target, :post,
        '/oauth/token', Util.encode_form(params), headers))
    raise BadResponse unless reply[jkey :token_type] && reply[jkey :access_token]
    TokenInfo.new(reply)
  end
1343034
def get_access_token(self, code, client_id, client_secret):
        ''' 
        
        '''
        headers = {
                'Content-Type' : 'application/json'
                }
        data = {
                'client_id' : client_id,
                'client_secret' : client_secret,
                'code' : code,
                }
        str_data = json.dumps(data)
        response = requests.request(method='POST', url=ACCESS_TOKEN_URL, headers=headers, data=str_data)
        status_code = response.status_code
        if status_code != 200:
            raise ValueError("{} -- {}".format(status_code, response.json()))
        return body['access_token']
356512
function(req, res, next) {
    var accessTokenUrl = 'https://github.com/login/oauth/access_token';
    var params = {
      code: req.body.code,
      client_id: req.body.clientId,
      client_secret: config.GITHUB_SECRET,
      redirect_uri: req.body.redirectUri
    };

    request.get({ url: accessTokenUrl, qs: params }, function(err, response, accessToken) {
      if (err) {
        res.status(500).send(err);
        return;
      }
      req.accessToken = qs.parse(accessToken);
      next();
    });
  }
1359913
def core_oauth_token_create(self, data, **kwargs):
        ""
        api_path = "/oauth/tokens"
        return self.call(api_path, method="POST", data=data, **kwargs)
139901
def _api_action(url, req, data=None):
    """"""
    requisite_headers = {'Accept': 'application/json',
                         'Content-Type': 'application/json'}
    auth = (user, token)

    if req == "GET":
        response = requests.get(url, headers=requisite_headers, auth=auth)
    elif req == "PUT":
        response = requests.put(url, headers=requisite_headers, auth=auth,
                                data=data)
    elif req == "POST":
        response = requests.post(url, headers=requisite_headers, auth=auth,
                                 data=data)
    elif req == "DELETE":
        response = requests.delete(url, headers=requisite_headers, auth=auth)

    return response.status_code, response.text
942535
public function getAccessToken(string $session_token):AccessToken{

		$params = [
			'method'  => 'auth.getSession',
			'format'  => 'json',
			'api_key' => $this->options->key,
			'token'   => $session_token,
		];

		$params['api_sig'] = $this->getSignature($params);

		$request = $this->requestFactory
			->createRequest('GET', Psr7\merge_query($this->apiURL, $params));


		return $this->parseTokenResponse($this->http->sendRequest($request));
	}
686469
def get_access_token(client_id, client_secret):
	'''
	
	'''

	headers = {'Content-Type': 'application/x-www-form-urlencoded'}
	payload = {
		'client_id': client_id,
		'client_secret': client_secret
	}

	request = requests.post(token_url, data=payload, headers=headers)
	if request.status_code == 200:
		token = request.json()
		return token

	return {'status': request.status_code, "message": request.text}
1312070
def build_access_token(response, access_token_opts, access_token_class)
      access_token_class.from_hash(self, response.parsed.merge(access_token_opts)).tap do |access_token|
        access_token.response = response if access_token.respond_to?(:response=)
      end
    end
142729
def _BuildToken(self, request, execution_time):
    """"""
    token = access_control.ACLToken(
        username=request.user,
        reason=request.args.get("reason", ""),
        process="GRRAdminUI",
        expiry=rdfvalue.RDFDatetime.Now() + execution_time)

    for field in ["Remote_Addr", "X-Forwarded-For"]:
      remote_addr = request.headers.get(field, "")
      if remote_addr:
        token.source_ips.append(remote_addr)
    return token
508667
async def get_access_token(self, code, loop=None, redirect_uri=None, **payload):
        
        # Possibility to provide REQUEST DATA to the method
        payload.setdefault('grant_type', 'authorization_code')
        payload.update({'client_id': self.client_id, 'client_secret': self.client_secret})

        if not isinstance(code, str) and self.shared_key in code:
            code = code[self.shared_key]
        payload['refresh_token' if payload['grant_type'] == 'refresh_token' else 'code'] = code

        redirect_uri = redirect_uri or self.params.get('redirect_uri')
        if redirect_uri:
            payload['redirect_uri'] = redirect_uri

        self.access_token = None
        data = await self.request('POST', self.access_token_url, data=payload, loop=loop)

        try:
            self.access_token = data['access_token']

        except KeyError:
            self.logger.error(
                'Error when getting the access token.\nData returned by OAuth server: %r',
                data,
            )
            raise web.HTTPBadRequest(reason='Failed to obtain OAuth access token.')

        return self.access_token, data
1266472
def request(method, path, opts = {})
      raise ClientError, 'Access token missing' unless @access_token

      opts[:headers] = {} if opts[:headers].nil?
      opts[:headers]['Accept'] = 'application/json'
      opts[:headers]['Content-Type'] = 'application/json' unless method == :get
      opts[:headers]['User-Agent'] = user_agent
      opts[:headers]['Authorization'] = "Bearer #{@access_token}"

      if !opts[:data].nil?
        opts[:body] = opts[:data].to_param

        puts "SETTING BODY #{opts[:body]}"

        opts[:headers]['Content-Type'] = 'application/x-www-form-urlencoded' # sob sob
      end

      path = URI.encode(path)

      resp = connection.run_request(method, path, opts[:body], opts[:headers]) do |req|
        req.params = opts[:params] if !opts[:params].nil?
      end

      response = Response.new(resp)

      case response.status
      when 301, 302, 303, 307
        # TODO
      when 200..299, 300..399
        # on non-redirecting 3xx statuses, just return the response
        response
      when 400..599
        error = ApiError.new(response)
        raise(error, "Status code #{response.status}")
      else
        error = ApiError.new(response)
        raise(error, "Unhandled status code value of #{response.status}")
      end
    end
955329
private function _generateAccessToken()
	{
		// Set the parameters.
		$parameters = array(
			'oauth_token' => $this->token['key']
		);

		if (strcmp($this->version, '1.0a') === 0)
		{
			$parameters = array_merge($parameters, array('oauth_verifier' => $this->token['verifier']));
		}

		// Make an OAuth request for the Access Token.
		$response = $this->oauthRequest($this->getOption('accessTokenURL'), 'POST', $parameters);

		parse_str($response->body, $params);

		// Save the access token.
		$this->token = array('key' => $params['oauth_token'], 'secret' => $params['oauth_token_secret']);
	}
133499
def call_api(self, path, **kwargs):
        '''
        
        '''
        if 'key' not in kwargs:
            kwargs['key'] = self.api_key
        req = requests.get('{0}{1}'.format(self.base_url, path), params=kwargs)

        if req.status_code != requests.codes.ok:
            req.raise_for_status()

        return req.json()
439171
def get_access_token(self, request, callback=None):
        ""
        raw_token = request.session.get(self.session_key, None)
        verifier = request.GET.get('oauth_verifier', None)
        if raw_token is not None and verifier is not None:
            data = {'oauth_verifier': verifier}
            callback = request.build_absolute_uri(callback or request.path)
            callback = force_text(callback)
            try:
                response = self.request('post', self.provider.access_token_url,
                                        token=raw_token, data=data, oauth_callback=callback)
                response.raise_for_status()
            except RequestException as e:
                logger.error('Unable to fetch access token: {0}'.format(e))
                return None
            else:
                return response.text
        return None