-
-
Notifications
You must be signed in to change notification settings - Fork 233
Auth updates for formplayer to allow automated app execution #34441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
c432a36
bff809f
eecf941
fe3f2db
42236ff
f16faf3
e3df8f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| from corehq.apps.domain.auth import ( | ||
| BASIC, | ||
| DIGEST, | ||
| FORMPLAYER, | ||
| NOAUTH, | ||
| API_KEY, | ||
| OAUTH2, | ||
|
|
@@ -33,6 +34,7 @@ | |
| login_or_basic_ex, | ||
| login_or_digest_ex, | ||
| login_or_api_key_ex, | ||
| login_or_formplayer_ex, | ||
| login_or_oauth2_ex, | ||
| two_factor_exempt, | ||
| ) | ||
|
|
@@ -338,65 +340,6 @@ def case_block_ok(case_updates): | |
| ) | ||
|
|
||
|
|
||
| @login_or_digest_ex(allow_cc_users=True) | ||
| @two_factor_exempt | ||
| @set_request_duration_reporting_threshold(60) | ||
| def _secure_post_digest(request, domain, app_id=None): | ||
| """only ever called from secure post""" | ||
| return _process_form( | ||
| request=request, | ||
| domain=domain, | ||
| app_id=app_id, | ||
| user_id=request.couch_user.get_id, | ||
| authenticated=True, | ||
| ) | ||
|
|
||
|
|
||
| @handle_401_response | ||
| @login_or_basic_ex(allow_cc_users=True) | ||
| @two_factor_exempt | ||
| @set_request_duration_reporting_threshold(60) | ||
| def _secure_post_basic(request, domain, app_id=None): | ||
| """only ever called from secure post""" | ||
| return _process_form( | ||
| request=request, | ||
| domain=domain, | ||
| app_id=app_id, | ||
| user_id=request.couch_user.get_id, | ||
| authenticated=True, | ||
| ) | ||
|
|
||
|
|
||
| @handle_401_response | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this isn't necessary on this view since the decorator only support basic auth |
||
| @login_or_oauth2_ex(allow_cc_users=True, oauth_scopes=['sync']) | ||
| @two_factor_exempt | ||
| @set_request_duration_reporting_threshold(60) | ||
| def _secure_post_oauth2(request, domain, app_id=None): | ||
| """only ever called from secure post""" | ||
| return _process_form( | ||
| request=request, | ||
| domain=domain, | ||
| app_id=app_id, | ||
| user_id=request.couch_user.get_id, | ||
| authenticated=True, | ||
| ) | ||
|
|
||
|
|
||
| @login_or_api_key_ex() | ||
| @require_permission(HqPermissions.edit_data) | ||
| @require_permission(HqPermissions.access_api) | ||
| @set_request_duration_reporting_threshold(60) | ||
| def _secure_post_api_key(request, domain, app_id=None): | ||
| """only ever called from secure post""" | ||
| return _process_form( | ||
| request=request, | ||
| domain=domain, | ||
| app_id=app_id, | ||
| user_id=request.couch_user.get_id, | ||
| authenticated=True, | ||
| ) | ||
|
|
||
|
|
||
| @waf_allow('XSS_BODY') | ||
| @location_safe | ||
| @csrf_exempt | ||
|
|
@@ -405,23 +348,60 @@ def _secure_post_api_key(request, domain, app_id=None): | |
| @set_request_duration_reporting_threshold(60) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I notice this decorator is on both the parent and the child views. Is it perhaps that one of the decorators doesn't call |
||
| def secure_post(request, domain, app_id=None): | ||
| authtype_map = { | ||
| DIGEST: _secure_post_digest, | ||
| BASIC: _secure_post_basic, | ||
| NOAUTH: _noauth_post, | ||
| API_KEY: _secure_post_api_key, | ||
| OAUTH2: _secure_post_oauth2, | ||
| DIGEST: [ | ||
| two_factor_exempt, | ||
| login_or_digest_ex(allow_cc_users=True), | ||
| ], | ||
| BASIC: [ | ||
| two_factor_exempt, | ||
| login_or_basic_ex(allow_cc_users=True), | ||
| handle_401_response, | ||
| ], | ||
| API_KEY: [ | ||
| require_permission(HqPermissions.edit_data), | ||
| require_permission(HqPermissions.access_api), | ||
| login_or_api_key_ex(), | ||
| ], | ||
| OAUTH2: [ | ||
| two_factor_exempt, | ||
| login_or_oauth2_ex(allow_cc_users=True, oauth_scopes=['sync']), | ||
| ], | ||
| FORMPLAYER: [ | ||
| two_factor_exempt, | ||
| login_or_formplayer_ex(allow_cc_users=True) | ||
| ], | ||
| } | ||
|
|
||
| if request.GET.get('authtype'): | ||
| authtype = request.GET['authtype'] | ||
| else: | ||
| authtype = determine_authtype_from_request(request, default=BASIC) | ||
|
|
||
| if authtype == NOAUTH: | ||
| return _noauth_post(request, domain, app_id=app_id) | ||
|
|
||
| try: | ||
| decorated_view = authtype_map[authtype] | ||
| decorators = authtype_map[authtype] | ||
| except KeyError: | ||
| return HttpResponseBadRequest( | ||
| 'authtype must be one of: {0}'.format(','.join(authtype_map)) | ||
| ) | ||
|
|
||
| return decorated_view(request, domain, app_id=app_id) | ||
| @set_request_duration_reporting_threshold(60) | ||
| def decorated_view(request, domain, app_id): | ||
| return _process_form( | ||
| request=request, | ||
| domain=domain, | ||
| app_id=app_id, | ||
| user_id=request.couch_user.get_id, | ||
| authenticated=True, | ||
| ) | ||
|
|
||
| for decorator in decorators: | ||
| decorated_view = decorator(decorated_view) | ||
|
|
||
| return decorated_view( | ||
| request=request, | ||
| domain=domain, | ||
| app_id=app_id, | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's tricky