Register a request at the consent service

        :type consent_args: dict
        :rtype: str

        :param consent_args: All necessary parameters for the consent request
        :return: Ticket received from the consent service
176753
def _consent_registration(self, consent_args):
        
        jws = JWS(json.dumps(consent_args), alg=self.signing_key.alg).sign_compact([self.signing_key])
        request = "{}/creq/{}".format(self.api_url, jws)
        res = requests.get(request)

        if res.status_code != 200:
            raise UnexpectedResponseError("Consent service error: %s %s", res.status_code, res.text)

        return res.text
458696
def pre_dispatch(self, request, path_args):
        
        secret_key = self.get_secret_key(request, path_args)
        if not secret_key:
            raise PermissionDenied('Signature not valid.')

        try:
            signing.verify_url_path(request.path, request.GET, secret_key)
        except SigningError as ex:
            raise PermissionDenied(str(ex))
891841
def prepare_request(self, *args, **kw):
        
        self.http_request = self.request_class(self.path, *args, **kw)
1319820
def add_permission(self, resource, operation):
        ''''''
        if isclass(resource):
            model_type = resource
            pk = ''
        else:
            model_type = resource.__class__
            pk = resource.pkvalue()
        p = Permission(model_type=model_type, object_pk=pk,
                       operation=operation)
        session = self.session
        if session.transaction:
            session.add(p)
            self.permissions.add(p)
            return p
        else:
            with session.begin() as t:
                t.add(p)
                self.permissions.add(p)
            return t.add_callback(lambda r: p)
1100648
def rpc(self, request, args):
        
        if request.method != 'POST':
            return self.error(405, request)
        payload = request.get_data(as_text=True) or '{}'
        request_method = request.args.get('method')
        if not request_method:
            return self.error(
                400, request,
                message="A query string parameter method= is missing."
            )
        name_map = self.service.__nirum_method_names__
        try:
            method_facial_name = name_map.behind_names[request_method]
        except KeyError:
            return self.error(
                400,
                request,
                message="Service doesn't have procedure named '{}'.".format(
                    request_method
                )
            )
        try:
            service_method = getattr(self.service, method_facial_name)
        except AttributeError:
            return self.error(
                400,
                request,
                message="Service has no procedure '{}'.".format(
                    request_method
                )
            )
        if not callable(service_method):
            return self.error(
                400, request,
                message="Remote procedure '{}' is not callable.".format(
                    request_method
                )
            )
        try:
            request_json = json.loads(payload)
        except ValueError:
            return self.error(
                400,
                request,
                message="Invalid JSON payload: '{}'.".format(payload)
            )
        type_hints = self.service.__nirum_service_methods__[method_facial_name]
        try:
            arguments = self._parse_procedure_arguments(
                type_hints,
                request_json
            )
        except (NirumProcedureArgumentValueError,
                NirumProcedureArgumentRequiredError) as e:
            return self.error(400, request, message=str(e))
        method_error_types = self.service.__nirum_method_error_types__
        if not callable(method_error_types):  # generated by older compiler
            method_error_types = method_error_types.get
        method_error = method_error_types(method_facial_name, ())
        try:
            result = service_method(**arguments)
        except method_error as e:
            return self._raw_response(400, serialize_meta(e))
        return_type = type_hints['_return']
        if type_hints.get('_v', 1) >= 2:
            return_type = return_type()
        if not self._check_return_type(return_type, result):
            return self.error(
                400,
                request,
                message="Incorrect return type '{0}' "
                        "for '{1}'. expected '{2}'.".format(
                            typing._type_repr(result.__class__),
                            request_method,
                            typing._type_repr(return_type)
                        )
            )
        else:
            return self._raw_response(200, serialize_meta(result))
500398
def authenticate(self, request, ticket, service):
        

        User = get_user_model()
        username = _verify(ticket, service)

        if not username:
            return None

        try:
            user = User.objects.get(username__iexact=username)
        except User.DoesNotExist:
            # user will have an "unusable" password
            if settings.CAS_AUTO_CREATE_USER:
                user = User.objects.create_user(username, '')
                user.save()
            else:
                user = None
        return user
794210
def options(self, request, *args, **kwargs):
        
        response = HttpResponse()
        response['Allow'] = ', '.join(self.allowed_methods)
        response['Content-Length'] = 0
        return response
1081009
def get(self, request):
        
        next_page = request.GET.get('next')
        required = request.GET.get('required', False)

        service_url = get_service_url(request, next_page)
        client = get_cas_client(service_url=service_url, request=request)

        if not next_page and settings.CAS_STORE_NEXT and 'CASNEXT' in request.session:
            next_page = request.session['CASNEXT']
            del request.session['CASNEXT']

        if not next_page:
            next_page = get_redirect_url(request)

        if request.user.is_authenticated:
            if settings.CAS_LOGGED_MSG is not None:
                message = settings.CAS_LOGGED_MSG % request.user.get_username()
                messages.success(request, message)
            return self.successful_login(request=request, next_page=next_page)

        ticket = request.GET.get('ticket')
        if ticket:
            user = authenticate(ticket=ticket,
                                service=service_url,
                                request=request)
            pgtiou = request.session.get("pgtiou")
            if user is not None:
                auth_login(request, user)
                if not request.session.exists(request.session.session_key):
                    request.session.create()
                SessionTicket.objects.create(
                    session_key=request.session.session_key,
                    ticket=ticket
                )

                if pgtiou and settings.CAS_PROXY_CALLBACK:
                    # Delete old PGT
                    ProxyGrantingTicket.objects.filter(
                        user=user,
                        session_key=request.session.session_key
                    ).delete()
                    # Set new PGT ticket
                    try:
                        pgt = ProxyGrantingTicket.objects.get(pgtiou=pgtiou)
                        pgt.user = user
                        pgt.session_key = request.session.session_key
                        pgt.save()
                    except ProxyGrantingTicket.DoesNotExist:
                        pass

                if settings.CAS_LOGIN_MSG is not None:
                    name = user.get_username()
                    message = settings.CAS_LOGIN_MSG % name
                    messages.success(request, message)
                return self.successful_login(request=request, next_page=next_page)
            elif settings.CAS_RETRY_LOGIN or required:
                return HttpResponseRedirect(client.get_login_url())
            else:
                raise PermissionDenied(_('Login failed.'))
        else:
            if settings.CAS_STORE_NEXT:
                request.session['CASNEXT'] = next_page
            return HttpResponseRedirect(client.get_login_url())
1087199
def register(self, request_class: Request, mapper_func: Callable[[Request], BrightsideMessage]) -> None:
        

        key = request_class.__name__
        if key not in self._registry:
            self._registry[key] = mapper_func
        else:
            raise ConfigurationException("There is already a message mapper defined for this key; there can be only one")
31631
def get(self, request):
        ''''''
        user = request.user
        serializer = PermissionsUserSerializer(
            instance=user, context={'request': request})
        return Response(data=serializer.data)
1184295
def register_account(self, username, service):
        
        data = {
            'service': service,
            'username': username,
        }

        return self._perform_post_request(self.register_account_endpoint, data, self.token_header)
1149008
def addRequest(self, service, *args):
        
        wrapper = RequestWrapper(self, '/%d' % self.request_number,
            service, *args)

        self.request_number += 1
        self.requests.append(wrapper)

        if self.logger:
            self.logger.debug('Adding request %s%r', wrapper.service, args)

        return wrapper
217124
def validate_proxy_granting_ticket(pgt, target_service):
    
    logger.debug("Proxy ticket request received for %s using %s" % (target_service, pgt))

    pgt = ProxyGrantingTicket.objects.validate_ticket(pgt, target_service)
    pt = ProxyTicket.objects.create_ticket(service=target_service, user=pgt.user, granted_by_pgt=pgt)
    return pt
270654
def add_request_participants(self, issue_id_or_key, users_list):
        
        url = 'rest/servicedeskapi/request/{}/participant'.format(issue_id_or_key)
        data = {'usernames': users_list}

        return self.post(url, data=data)
826255
def request(self, *args, **kwargs):
        
        return RequestsHandler(*args, api_token=self.api_token,
                               verify=self.mist_client.verify,
                               job_id=self.mist_client.job_id, **kwargs)
863860
def add_approval(self, reason):
        
        if not isinstance(reason, basestring):
            raise TypeError("reason can only be an instance of type basestring")
        self._call("addApproval",
                     in_p=[reason])
46054
def _register_procedure(self, procedure_name, invocation_policy="single"):
        
        options = {"invoke": invocation_policy}
        message = Register(procedure=procedure_name, options=options)
        request_id = message.request_id

        try:
            self.send_message(message)
        except ValueError:
            raise WampProtocolError(
                "failed to register callee: %s", procedure_name
            )

        self.request_ids[request_id] = procedure_name