示例#1
0
 def _error_redirect(self, error_code, end_point):
     """Redirect the user to the endpoint, save the error
     status to the storage under the token"""
     token = generate_token()
     self.storage.store(token, error_dict(error_code), expires=300)
     form_html = redirect_form(end_point, token)
     return Response(body=autoSubmitHTML(form_html))
示例#2
0
 def _error_redirect(self, error_code, end_point):
     """Redirect the user to the endpoint, save the error
     status to the storage under the token"""
     token = generate_token()
     self.storage.store(token, error_dict(error_code), expires=300)
     form_html = redirect_form(end_point, token)
     return Response(body=autoSubmitHTML(form_html))
示例#3
0
文件: server.py 项目: miing/mci_migo
def _django_response(request, oresponse, auth_success=False, orequest=None):
    """ Convert an OpenID response into a Django HttpResponse """
    webresponse = _get_openid_server().encodeResponse(oresponse)
    # This is a workaround for the fact the the openid library returns bare
    # HTML form markup instead of a complete HTML document. See
    # https://github.com/openid/python-openid/pull/31/files which has been
    # merged, but not released.
    if webresponse.body and oresponse.request.mode in BROWSER_REQUEST_MODES:
        response = HttpResponse(
            oidutil.autoSubmitHTML(webresponse.body), mimetype='text/html')
    else:
        response = HttpResponse(webresponse.body, mimetype='text/plain')
    response.status_code = webresponse.code
    for key, value in webresponse.headers.items():
        response[key] = value
        logger.debug("response[%s] = %s" % (key, value))
    logger.debug("response_body = " + webresponse.body)
    if auth_success and isinstance(oresponse.request, CheckIDRequest):
        logger.debug("oresponse.fields = " + str(oresponse.fields))
        approved_data = _get_approved_data(request, orequest)
        OpenIDRPSummary.objects.record(
            request.user,
            oresponse.request.trust_root,
            None,
            approved_data)
    return response
示例#4
0
 def _success_redirect(self, user_data, end_point):
     """Redirect the user to the endpoint, save the user_data to a new
     random token in storage"""
     # Generate the token, store the extracted user-data for 5 mins, and send back
     token = generate_token()
     self.storage.store(token, user_data, expires=300)
     form_html = redirect_form(end_point, token)
     return Response(body=autoSubmitHTML(form_html))
示例#5
0
 def _success_redirect(self, user_data, end_point):
     """Redirect the user to the endpoint, save the user_data to a new
     random token in storage"""
     # Generate the token, store the extracted user-data for 5 mins, and send back
     token = generate_token()
     log.debug("About to store %s = %s using self.storage.store" %
               (token, user_data))
     self.storage.store(token, user_data, expires=300)
     form_html = redirect_form(end_point, token)
     return Response(body=autoSubmitHTML(form_html))
示例#6
0
def openid_respond(openid_response):
    request.delete_transaction_after_request()
    try:
        webresponse = get_server().encodeResponse(openid_response)
        # This is a VERY ugly hack, but is required because the version of
        # python-openid in EPEL6 does not use the auto-submit encoder, but
        # only the toFormMarkup encoder.....
        if '<form' in webresponse.body and 'onload' not in webresponse.body:
            webresponse.body = oidutil.autoSubmitHTML(webresponse.body)
        logger.debug('Responding with :%s', webresponse)
        return (webresponse.body, webresponse.code, webresponse.headers)
    except server.EncodingError, why:
        logger.warning('Unable to respond with response: %s', why)
        headers = {'Content-type': 'text/plain; charset=UTF-8'}
        return why.response.encodeToKVForm(), 400, headers
示例#7
0
def openid_respond(openid_response):
    request.delete_transaction_after_request()
    try:
        webresponse = get_server().encodeResponse(openid_response)
        # This is a VERY ugly hack, but is required because the version of
        # python-openid in EPEL6 does not use the auto-submit encoder, but
        # only the toFormMarkup encoder.....
        if '<form' in webresponse.body and 'onload' not in webresponse.body:
            webresponse.body = oidutil.autoSubmitHTML(webresponse.body)
        logger.debug('Responding with :%s', webresponse)
        return (webresponse.body, webresponse.code, webresponse.headers)
    except server.EncodingError, why:
        logger.warning('Unable to respond with response: %s', why)
        headers = {'Content-type': 'text/plain; charset=UTF-8'}
        return why.response.encodeToKVForm(), 400, headers