Handle token requests (served at /token).
        :type context: satosa.context.Context
        :rtype: oic.utils.http_util.Response

        :param context: the current context
        :return: HTTP response to the client
499220
def token_endpoint(self, context):
        
        headers = {"Authorization": context.request_authorization}
        try:
            response = self.provider.handle_token_request(urlencode(context.request), headers)
            return Response(response.to_json(), content="application/json")
        except InvalidClientAuthentication as e:
            logger.debug('invalid client authentication at token endpoint', exc_info=True)
            error_resp = TokenErrorResponse(error='invalid_client', error_description=str(e))
            response = Unauthorized(error_resp.to_json(), headers=[("WWW-Authenticate", "Basic")],
                                    content="application/json")
            return response
        except OAuthError as e:
            logger.debug('invalid request: %s', str(e), exc_info=True)
            error_resp = TokenErrorResponse(error=e.oauth_error, error_description=str(e))
            return BadRequest(error_resp.to_json(), content="application/json")
12784
def _handle_response(self):
        
        _logger.debug("Handling response from GitHub")
        params = {
            'code': request.args.get('code'),
            'client_id': self.client_id,
            'client_secret': self.client_secret
        }
        url = self.auth_url + 'access_token'
        _logger.debug("POSTing to %s", url)
        _logger.debug(params)
        response = self.session.post(url, data=params)
        data = parse_qs(response.content)
        _logger.debug("response.content = %s", data)
        for k, v in data.items():
            if len(v) == 1:
                data[k] = v[0]
        token = data.get(b'access_token', None)
        if token is not None:
            token = token.decode('ascii')
        return token
75628
def __handle_request(self, request, *args, **kw):
        

        self._authenticate(request)
        self._check_permission(request)
        method = self._get_method(request)
        data = self._get_input_data(request)
        data = self._clean_input_data(data, request)
        response = self._exec_method(method, request, data, *args, **kw)
        return self._process_response(response, request)
604499
def _handle_satosa_authentication_error(self, error):
        
        context = Context()
        context.state = error.state
        frontend = self.module_router.frontend_routing(context)
        return frontend.handle_backend_error(error)
296479
def _get_content(self, context):
        
        self._valid_template()
        context.update({
            "csrf_token_value": get_token(self.request)
        })
        return render_to_string(self.get_template_names(), context)
390346
def _prepare(cls, context: Dict) -> Dict:
        
        if not context and cls.raise_empty_context:
            raise PolyaxonActionException('{} received invalid payload context.'.format(cls.name))

        return context
1181334
public final void handleMessageReceived(HttpRequestContext context, long bytes) {
    checkNotNull(context, "context");
    context.receiveMessageSize.addAndGet(bytes);
    if (context.span.getOptions().contains(Options.RECORD_EVENTS)) {
      // record compressed size
      recordMessageEvent(
          context.span, context.receviedSeqId.addAndGet(1L), Type.RECEIVED, bytes, 0L);
    }
  }
690078
async def dispatch_request(
        self, request_context: Optional[RequestContext]=None,
    ) -> ResponseReturnValue:
        
        request_ = (request_context or _request_ctx_stack.top).request
        if request_.routing_exception is not None:
            raise request_.routing_exception

        if request_.method == 'OPTIONS' and request_.url_rule.provide_automatic_options:
            return await self.make_default_options_response()

        handler = self.view_functions[request_.url_rule.endpoint]
        return await handler(**request_.view_args)
85628
def render_json_response(self, context, status=200):
        
        json_context = json.dumps(context, cls=self.json_encoder_class)

        return HttpResponse(json_context,
                            content_type=self.get_content_type(),
                            status=status)
806032
def callback(self, request, **kwargs):
        
        access_token = Pocket.get_access_token(consumer_key=self.consumer_key, code=request.session['request_token'])
        kwargs = {'access_token': access_token}
        return super(ServicePocket, self).callback(request, **kwargs)
397517
def render_to_response(self, context, **response_kwargs):
        
        return HttpResponse(json.dumps(context, cls=JSON_ENCODER), 
                            content_type='application/json',
                            **response_kwargs)
647173
def request(self, method, url, **kwargs):
        

        if "data" in kwargs:
            kwargs["data"] = json.dumps(kwargs["data"])

        kwargs["headers"] = {
            'Content-Type': 'application/json',
            'Authorization': 'token %s' % self.__token__,
        }
        req = make_request(
            method,
            url,
            **kwargs
        )
        self.logger.debug(
            "Request::{}::{}".format(method, url),
            extra={
                "request": kwargs,
                "response": {"headers": req.headers, "code": req.status_code, "data": req.content}
            }
        )
        return req
360933
def handle_exception(self, exc):
        
        if isinstance(exc, (exceptions.NotAuthenticated,
                            exceptions.AuthenticationFailed)):
            # WWW-Authenticate header for 401 responses, else coerce to 403
            auth_header = self.get_authenticate_header(self.request)

            if auth_header:
                exc.auth_header = auth_header
            else:
                exc.status_code = status.HTTP_403_FORBIDDEN

        exception_handler = self.settings.EXCEPTION_HANDLER

        context = self.get_exception_handler_context()
        response = exception_handler(exc, context)

        if response is None:
            raise

        response.exception = True
        return response
1338976
def post(self):
        
        res = {"success": False}
        #1.
        token = request.cookies.get("token") or request.headers.get("authentication")
        if not token:
            return res
        #2.
        try:
            self.jwt.verifyJWT(token)
        except JWTException as e:
            self.logger.exception(e, exc_info=True)
        else:
            res.update(success=True)
        return res
468226
def request(params, &block)
      cached_token = check_cache(request_params(params))
      return cached_token if cached_token
      cache_response(request_no_cache(request_params(params), &block))
    end
448586
def _check_error_response(self, response, context):
        
        if "error" in response:
            satosa_logging(logger, logging.DEBUG, "%s error: %s %s" %
                           (type(response).__name__, response["error"], response.get("error_description", "")),
                           context.state)
            raise SATOSAAuthenticationError(context.state, "Access denied")
61618
def _on_access_token(self, future, response):
        
        LOGGER.info(response.body)
        content = escape.json_decode(response.body)
        if 'error' in content:
            LOGGER.error('Error fetching access token: %s', content['error'])
            future.set_exception(auth.AuthError('StackExchange auth error: %s' %
                                                str(content['error'])))
            return
        callback = self.async_callback(self._on_stackexchange_user, future,
                                       content['access_token'])
        self.stackexchange_request('me', callback, content['access_token'])