I am trying to enable SAML in Hue™ 4.1 and have an error. The issue is the connection goes from https to http as the below setup: user–>https://hue.xyz.com:8889 --> LTM loadbalancer --> http://ip-addr:8889 (no SSL enabled in HUE).
The SAML IDP login pages comes up and when trying to login HUE returns error: Bad Request (400) . In the /var/log/hue/runcpserver.log I see below errors. The /saml2/metadata xml shows http not https in the ACS url <md:AssertionConsumerService Binding=“urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST” Location=“http://hue.xyz.com:8889/saml2/acs/” index=“1”/>. Any thoughts?
[17/Dec/2019 09:58:58 -0800] response ERROR https://hue.xyz.com:8889/saml2/acs/ not in [‘http://hue.xyz.com:8889/saml2/acs/’]
[17/Dec/2019 09:58:58 -0800] views WARNING Invalid SAML Assertion received (unknown error).
[17/Dec/2019 09:58:58 -0800] middleware INFO Processing exception: : Traceback (most recent call last):
File “/opt/cloudera/parcels/CDH-5.15.1-1.cdh5.15.1.p0.4/lib/hue/build/env/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/core/handlers/base.py”, line 112, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File “/opt/cloudera/parcels/CDH-5.15.1-1.cdh5.15.1.p0.4/lib/hue/build/env/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/db/transaction.py”, line 371, in inner
return func(*args, **kwargs)
File “/opt/cloudera/parcels/CDH-5.15.1-1.cdh5.15.1.p0.4/lib/hue/build/env/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/views/decorators/http.py”, line 41, in inner
return func(request, *args, **kwargs)
File “/opt/cloudera/parcels/CDH-5.15.1-1.cdh5.15.1.p0.4/lib/hue/build/env/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/views/decorators/csrf.py”, line 57, in wrapped_view
return view_func(*args, **kwargs)
File “/opt/cloudera/parcels/CDH-5.15.1-1.cdh5.15.1.p0.4/lib/hue/build/env/lib/python2.7/site-packages/djangosaml2-0.16.4-py2.7.egg/djangosaml2/views.py”, line 276, in assertion_consumer_service
return fail_acs_response(request, status=400, exc_class=SuspiciousOperation)
File “/opt/cloudera/parcels/CDH-5.15.1-1.cdh5.15.1.p0.4/lib/hue/build/env/lib/python2.7/site-packages/djangosaml2-0.16.4-py2.7.egg/djangosaml2/utils.py”, line 85, in fail_acs_response
return failure_function(request, *args, **kwargs)
File “/opt/cloudera/parcels/CDH-5.15.1-1.cdh5.15.1.p0.4/lib/hue/build/env/lib/python2.7/site-packages/djangosaml2-0.16.4-py2.7.egg/djangosaml2/acs_failures.py”, line 22, in exception_failure
raise exc_class
SuspiciousOperation
[17/Dec/2019 09:58:58 -0800] access INFO 10.83.175.203 -anon- - “POST /saml2/acs/ HTTP/1.1” returned in 72ms
This was resolved by adding the below in the Cloudera Manager Hue Service Advanced Configuration Snippet (Safety Valve) for hue_safety_valve.ini
base_url=https://hue.xyz.com:8889
Related
this is my views.py
#api_view(http_method_names=['POST'])
#permission_classes([AllowAny])
#psa()
def exchange_token(request, backend):
serializer = UserSerializer(data=request.data)
if serializer.is_valid(raise_exception=True):
user = request.backend.do_auth(serializer.validated_data['access_token'])
if user:#drf built in token authentication??
token, _ = Token.objects.get_or_create(user=user) # drf token authentication
return Response({'token':token.key})
else:
return Response(
{'errors':{'token':'Invalid token'}},
status = status.HTTP_400_BAD_REQUEST,
)
https://www.toptal.com/django/integrate-oauth-2-into-django-drf-back-end
I'm following this page and trying to request using postman
But above error happends.
I think I should pass "backend" argument when requesting, but I don't know what to do right now...
someone please tell me how can I solve this problem
Traceback (most recent call last):
File "/home/park/miniconda3/envs/wantu/lib/python3.8/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/home/park/miniconda3/envs/wantu/lib/python3.8/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/park/miniconda3/envs/wantu/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/home/park/miniconda3/envs/wantu/lib/python3.8/site-packages/django/views/generic/base.py", line 84, in view
return self.dispatch(request, *args, **kwargs)
File "/home/park/miniconda3/envs/wantu/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "/home/park/miniconda3/envs/wantu/lib/python3.8/site-packages/rest_framework/views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "/home/park/miniconda3/envs/wantu/lib/python3.8/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
raise exc
File "/home/park/miniconda3/envs/wantu/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "/home/park/miniconda3/envs/wantu/lib/python3.8/site-packages/rest_framework/decorators.py", line 50, in handler
return func(*args, **kwargs)
TypeError: wrapper() missing 1 required positional argument: 'backend'
full traceback error is here
it is my root urls.py
from django.urls import path, include
urlpatterns = [
path("users", include("users.urls")),
path('applications', include('applications.urls')),
path("jobs", include("jobs.urls")),
path('cv', include('cv.urls'))
]
and users.urls.py
urlpatterns = [
path("/kakao/login", views.exchange_token),
]
Your URL configuration is wrong - it's missing a backend named parameter. See this, from the code of the tutorial you are referring to:
The URL at which this view lives must include a backend field, like:
url(API_ROOT + r'social/(?P<backend>[^/]+)/$', exchange_token),
In your case, you need to add the backend parameter to the URL:
urlpatterns = [
path("/kakao/login/<str:backend>/", views.exchange_token),
]
On Linux Debian Bullseye, I am running a gulp HTML server on port 8081, and a Django backend on port 8083. I am trying to POST a relatively large JSON document from a static page using JQuery's AJAX feature. After properly setting up the django-cors-headers module, with MIDDLEWARE = [ "corsheaders.middleware.CorsMiddleware" ] , CORS_ALLOWED_ORIGINS and CSRF_TRUSTED_ORIGINS on settings.py, I coded the following HTML view on views.py, with the #csrf_exempt decorator in place since I'm running everything on localhost:
from django.views.decorators.csrf import csrf_exempt
#csrf_exempt
def processOrder(request):
leasing_order_unicode = request.body.decode("utf-8")
print(request.POST.__dict__)
print(request.POST["leasing_order"])
return HttpResponse(leasing_order_unicode, headers={ "Access-Control-Allow-Origin": "http://localhost:8081", "Content-Type": "application/json" })
Then I added it to urls.py as follows:
path("processorder", processOrder, name="processorder")
I expect my Django view to be able to access the JSON string with request.POST["leasing_order"]. Instead, I get errors and failures when attempting to access it.
Let serializedata() be a function that takes care of gathering all my local data into an object and then serializing it. If I POST my form data with multipart/form-data encoding as follows:
export function sendOrder_multipart()
{
let finalorder = serializedata();
let finalorder_postdata = new FormData();
finalorder_postdata.append("leasing_order", finalorder);
$.ajax({ method: "POST", url: "http://localhost:8083/orderstable/processorder",
data: finalorder_postdata, processData: false, contentType: "multipart/form-data" });
}
I get the following error on my Django backend's console output:
Bad request (Unable to parse request body): /orderstable/processorder
Traceback (most recent call last):
File "<project path>/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "<project path>/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "<project path>/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "<project path>/<website>/orderstable/views.py", line 54, in processOrder
print(request.POST.__dict__)
File "<project path>/lib/python3.9/site-packages/django/core/handlers/wsgi.py", line 102, in _get_post
self._load_post_and_files()
File "<project path>/lib/python3.9/site-packages/django/http/request.py", line 328, in _load_post_and_files
self._post, self._files = self.parse_file_upload(self.META, data)
File "<project path>/lib/python3.9/site-packages/django/http/request.py", line 287, in parse_file_upload
parser = MultiPartParser(META, post_data, self.upload_handlers, self.encoding)
File "<project path>/lib/python3.9/site-packages/django/http/multipartparser.py", line 76, in __init__
raise MultiPartParserError('Invalid boundary in multipart: %s' % force_str(boundary))
django.http.multipartparser.MultiPartParserError: Invalid boundary in multipart: None
[17/Dec/2021 20:29:11] "POST /orderstable/processorder HTTP/1.1" 400 143
If I tweak my Javascript frontend's function to not use multipart/form-data encoding, like this:
function sendOrder_nomultipart()
{
let finalorder = serializedata();
let finalorder_postdata = new FormData();
finalorder_postdata.append("leasing_order", finalorder);
$.ajax({ method: "POST", url: "http://localhost:8083/orderstable/processorder",
data: finalorder_postdata, processData: false });
}
I get a slightly different result, but still can't access my string through request.POST:
{'_encoding': 'UTF-8', '_mutable': False}
Internal Server Error: /orderstable/processorder
Traceback (most recent call last):
File "<project root>/lib/python3.9/site-packages/django/utils/datastructures.py", line 83, in __getitem__
list_ = super().__getitem__(key)
KeyError: 'leasing_order'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<project root>/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "<project root>/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "<project root>/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "<project root>/<website>/orderstable/views.py", line 55, in processOrder
print(request.POST["leasing_order"])
File "<project root>/lib/python3.9/site-packages/django/utils/datastructures.py", line 85, in __getitem__
raise MultiValueDictKeyError(key)
django.utils.datastructures.MultiValueDictKeyError: 'leasing_order'
[17/Dec/2021 20:35:59] "POST /orderstable/processorder HTTP/1.1" 500 106954
I found the solution after reproducing this issue with a minimum test case. To solve this issue, you must pass the POST data into $.ajax() as a simple object instead of using a FormData() object, and omit the contentType and processData fields of the configuration object.
Code that worked:
function sendOrder_thegoodone()
{
let finalorder = serializedata();
let finalorder_obj = { leasing_order: finalorder };
$.ajax(
{
method: "POST",
url: "http://localhost:8083/orderstable/processorder",
data: finalorder_obj
});
}
I am experimenting in Python to retrieve the saved searches in my space in Kibana.
I am trying to follow the example at https://www.elastic.co/guide/en/kibana/current/saved-objects-api-find.html
Here is my code.
r = requests.get('http://myhost.com:9200/s/guy-levin/api/saved_objects/_find?type=search',
auth=(username, password))
print(r.status_code)
print(r.text)
print(r.json())
I get the output:
400
{"error":"no handler found for uri [/s/guy-levin/api/saved_objects/_find?type=search] and method [GET]"}
{'error': 'no handler found for uri [/s/guy-levin/api/saved_objects/_find?type=search] and method [GET]'}
I also tried es.search(), but if I try es.search(doc_type='search') [not even sure if this is right; Internet searches not helpful thus far], I get a stack trace ending with:
elasticsearch.exceptions.AuthorizationException: AuthorizationException(403, 'security_exception', 'action [indices:data/read/search] is unauthorized for user [some_user_name]')
Changing port to 5601, I got this stack trace:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/git/KibanaReader/main.py", line 207, in <module>
get_saved_search('Blah Blah REST API')
File "C:/git/KibanaReader/main.py", line 90, in get_saved_search
r = requests.get('http://kbqa2.nayax.com:5601/s/guy-levin/api/saved_objects/_find?type=search',
File "C:\git\KibanaReader\venv\lib\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "C:\git\KibanaReader\venv\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\git\KibanaReader\venv\lib\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\git\KibanaReader\venv\lib\site-packages\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "C:\git\KibanaReader\venv\lib\site-packages\requests\adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
The Saved Object API is a Kibana API, so you need to target the Kibana endpoint (port 5601 by default), not the Elasticsearch endpoint (port 9200 by default).
The right URL should be
http://myhost.com:5601/s/guy-levin/api/saved_objects/_find?type=search
^
|
change this
This is my first post in Stack exchange, I am Python and Django Noob trying to develop an application. The application uses django-registration for user registration and then I started plugging in 'social' authentication. I chose allauth as it has the ability to perform authentication among'st other things.
I have hit the same problem that was presented in this thread: django allauth facebook redirects to signup when retrieved email matches an existing user's email?
user login/signup failing if the user with same email address already exists in the database(due to registration with local registration path). I tried the solution provided in the above post and have issues. Looking for some help and advise here.
I have exactly the same code as above in my socialadapter.py under the following path
myproject/allauth/socialaccount/socialadapter.py
I have the following in my settings
LOGIN_URL = '/'
#LOGIN_REDIRECT_URL = '/'
LOGIN_REDIRECT_URL = "/users/{id}/mytags"
SOCIALACCOUNT_QUERY_EMAIL = True
ACCOUNT_AUTHENTICATION_METHOD='username_email'
SOCIALACCOUNT_EMAIL_REQUIRED = False
#create and use specific adapter to handle the issue reported here
# https://github.com/pennersr/django-allauth/issues/418
ACCOUNT_ADAPTER = "myproject.allauth.socialaccount.MyLoginAccountAdapter"
SOCIALACCOUNT_ADAPTER = 'myproject.allauth.socialaccount.MySocialAccountAdapter'
On starting the runserver and accessing the facebook/login , I see the following issue
[17/Jul/2014 11:49:43] "GET /myproject/accounts2/facebook/login/ HTTP/1.1" 500 59
---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 58805) Traceback (most recent call last): File "C:\Python27\Lib\SocketServer.py", line 593, in process_request_thread
self.finish_request(request, client_address) File "C:\Python27\Lib\SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self) File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 139, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs) File "C:\Python27\Lib\SocketServer.py", line 651, in __init__
self.finish() File "C:\Python27\Lib\SocketServer.py", line 710, in finish
self.wfile.close() File "C:\Python27\Lib\socket.py", line 279, in close
self.flush() File "C:\Python27\Lib\socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size]) error: [Errno 10053] An established connection was aborted by the software in your host machine
---------------------------------------- ERROR:django.request:Internal Server Error: /myproject/accounts2/facebook/login/callback/ Traceback (most recent call last): File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 109, in get_response
response = callback(request, *callback_args, **callback_kwargs) File "myproject\allauth\socialaccount\providers\oauth2\views.py", line 51, in view
return self.dispatch(request, *args, **kwargs) File "myproject\allauth\socialaccount\providers\oauth2\views.py", line 98, in dispatch
response=access_token) File "myproject\allauth\socialaccount\providers\facebook\views.py", line 43, in complete_login
return fb_complete_login(request, app, access_token) File "myproject\allauth\socialaccount\providers\facebook\views.py", line 31, in fb_complete_login
.sociallogin_from_response(request, extra_data) File "myproject\allauth\socialaccount\providers\base.py", line 44, in sociallogin_from_response
adapter = get_adapter() File "myproject\allauth\socialaccount\adapter.py", line 150, in get_adapter
return import_attribute(app_settings.ADAPTER)() File "myproject\allauth\utils.py", line 97, in import_attribute
ret = getattr(importlib.import_module(pkg), attr) AttributeError: 'module' object has no attribute 'MySocialAccountAdapter' [17/Jul/2014 11:49:46] "GET /myproject/accounts2/facebook/login/callback/?code=AQBShGWTHnGVvlo-fOVW7xjF9RUJo-k7P23zISHC70p aAR5uWYpnI46gpHFUCC5Rz-SviDyTITVRAUkZ-DhkZaHyBT2n5UBhhSwkACgCKTTgPrFLAZFBQs05AEZ67xfk-wRlF47DSjT26bbDdUmc1ptfFxP3W4qS5Y6b5Yrj iLTI3RMScOEM0EKUQjNySyj4XSAVk6wj4HcAbCVxiVv5QaH63ayxyt5Y5jQ0AOH3zsCngPaqFNJArXseMS6wfqSc8yDwcwWZKo1nGhcNtA9Gy_bqZNiTZSjPJguhT lBwbmDAJ9SUNI8AS3yzC-AKDtD2_bo&state=441rn77wUuLH HTTP/1.1" 500 147978
Initially the socialadapter.py would not even compile,all others did compile even after deleting the .pyc
I referred to this thread: pycompile for python3.2
and force compile but I still see the issue
Any suggestions on what I might be doing wrong here is greatly appreciated.
thank you for your valuable time.
-km
EDIT:
Environment
Python 2.7.5
allauth: 0.17
Ok I figured out the issue , I had the settings entry for my adapter missing a the full path to the class. Now I am able to login using Facebook.
However I have another issue, I am trying to enable Linked in login for the same app and have the following entries in the settings
SOCIALACCOUNT_PROVIDERS = \
{'linkedin':{'SCOPE': [ 'r_emailaddress',
'r_fullprofile',
'r_emailaddress',
'r_contactinfo',
'r_network'],
'PROFILE_FIELDS':
[
'id',
'first-name',
'last-name',
'email-address',
'picture-url',
'public-profile-url',
'skills',
'headline',
'industry',
'num-connections',
'positions',
'interests',
'languages',
'certifications',
'educations',
'courses',
'three-current-positions',
'three-past-positions',
'recommendations-received',
'honors-awards'
]
},
'facebook': {'SCOPE': ['email', 'user_about_me', 'user_birthday',
'user_education_history','user_work_history',
'user_hometown',
'user_location',
'user_religion_politics','user_subscriptions',
'read_stream',
'read_insights',
'read_friendlists',
'user_likes',
'user_interests',
'user_groups'
],
'AUTH_PARAMS': {},
'METHOD': 'oauth2'
},
}
Now When I use the login page, I get the following error
[17/Jul/2014 22:26:28] "GET /myproject/accounts2/linkedin/login/?process=connect HTTP/1.1" 302 0
ERROR:django.request:Internal Server Error: /myproject/accounts2/linkedin/login/callback/
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 109, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "myproject\allauth\socialaccount\providers\oauth\views.py", line 35, in view
return self.dispatch(request, *args, **kwargs)
File "myproject\allauth\socialaccount\providers\oauth\views.py", line 90, in dispatch
return complete_social_login(request, login)
File "myproject\allauth\socialaccount\helpers.py", line 113, in complete_social_login
sociallogin=sociallogin)
File "C:\Python27\lib\site-packages\django\dispatch\dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "myproject\allauth\socialaccount\socialadapter.py", line 50, in link_to_local_user
email_address = sociallogin.account.extra_data['email']
KeyError: 'email'
[17/Jul/2014 22:26:50] "GET /myproject/accounts2/linkedin/login/callback/?oauth_token=77--d223fb8b-168f-4260-b93c-1a6e5ff2
e1e1&oauth_verifier=52724 HTTP/1.1" 500 139897
I am not sure how to fix this because the SCOPE for LinkedIn has : 'email-address', how can I fix this issue as the Email Fields in LinkedIn Documentation also says email-address
LinkedIn fields
Any suggestions are appreciated.
I am sorry I do not know how to put a bounty on the question and I do not have enough to place for the question also.
TIA
-km
I get this over and over again after running manage.py test:
ERROR 4280 140735184636256 base: Internal Server Error: /add/error/
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/views/decorators/cache.py", line 89, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/messages/tests/urls.py", line 30, in add
getattr(messages, message_type)(request, msg)
File "/Library/Python/2.7/site-packages/django/contrib/messages/api.py", line 102, in error
fail_silently=fail_silently)
File "/Library/Python/2.7/site-packages/django/contrib/messages/api.py", line 22, in add_message
raise MessageFailure('You cannot add messages without installing '
MessageFailure: You cannot add messages without installing django.contrib.messages.middleware.MessageMiddleware
MessageMiddleware is enabled in my settings.py so not sure why. Any clue?
You are running all defined tests, including django's own tests. Specify the modules that you want to test:
python manage.py test my_app my_other_app