def test_get_http_url(): url = u'https://localhost:8092/authorization' method = 'GET' values = {'acr_values': 'PASSWORD', 'state': 'urn:uuid:92d81fb3-72e8-4e6c-9173-c360b782148a', 'redirect_uri': 'https://localhost:8666/919D3F697FDAAF138124B83E09ECB0B7', 'response_type': 'code', 'client_id': 'ok8tx7ulVlNV', 'scope': 'openid profile email address phone'} request = AuthorizationRequest(**values) _url = util.get_http_url(url, request, method) _part = urlsplit(_url) _req = parse_qs(_part.query) assert set(_req.keys()) == {'acr_values', 'state', 'redirect_uri', 'response_type', 'client_id', 'scope'}
def get_request_parameters(self, request_args=None, method="", request_body_type="", authn_method='', **kwargs): """ Builds the request message and constructs the HTTP headers. This is the starting point for a pipeline that will: - construct the request message - add/remove information to/from the request message in the way a specific client authentication method requires. - gather a set of HTTP headers like Content-type and Authorization. - serialize the request message into the necessary format (JSON, urlencoded, signed JWT) :param request_body_type: Which serialization to use for the HTTP body :param method: HTTP method used. :param authn_method: Client authentication method :param request_args: Message arguments :param kwargs: extra keyword arguments :return: Dictionary with the necessary information for the HTTP request """ if not method: method = self.http_method if not authn_method: authn_method = self.get_authn_method() if not request_body_type: request_body_type = self.request_body_type request = self.construct_request(request_args=request_args, **kwargs) LOGGER.debug("Request: %s", request) _info = {'method': method} _args = kwargs.copy() if self.service_context.get('issuer'): _args['iss'] = self.service_context.get('issuer') # Client authentication by usage of the Authorization HTTP header # or by modifying the request object _headers = self.get_authn_header(request, authn_method, authn_endpoint=self.endpoint_name, **_args) # Find out where to send this request try: endpoint_url = kwargs['endpoint'] except KeyError: endpoint_url = self.get_endpoint() _info['url'] = get_http_url(endpoint_url, request, method=method) # If there is to be a body part if method == 'POST': # How should it be serialized if request_body_type == 'urlencoded': content_type = URL_ENCODED elif request_body_type in ['jws', 'jwe', 'jose']: content_type = JOSE_ENCODED else: # request_body_type == 'json' content_type = JSON_ENCODED _info['body'] = get_http_body(request, content_type) _headers.update({'Content-Type': content_type}) if _headers: _info['headers'] = _headers return _info