def cookie_for_token(t): app=t.share.with_app try: activity = AppActivity.objects.get(name="main", app=app) except AppActivity.DoesNotExist: activity = AppActivity.objects.get(app=app) app_index_req = utils.url_request_build(activity.url, "GET", {}, "") oauth_request = OAuthRequest(app, None, app_index_req, oauth_parameters=t.passalong_params) oauth_request.sign() auth = oauth_request.to_header()["Authorization"] return {'oauth_cookie' : auth}
def signed_header_for_token(t): app = t.share.with_app headers = {} app_index_req = utils.url_request_build(app.index_url, "GET", headers, "") # sign as a two-legged OAuth request for the app oauth_request = OAuthRequest( consumer=app, token=None, # no access tokens: 2-legged request http_request=app_index_req, oauth_parameters=t.passalong_params ) oauth_request.sign() auth = oauth_request.to_header()["Authorization"] return auth
def signed_header_for_token(t): app=t.share.with_app try: activity = AppActivity.objects.get(name="main", app=app) except AppActivity.DoesNotExist: activity = AppActivity.objects.get(app=app) headers = {} app_index_req = utils.url_request_build(activity.url, "GET", headers, "") # sign as a two-legged OAuth request for the app oauth_request = OAuthRequest(consumer=app, token=None, # no access tokens: 2-legged request http_request=app_index_req, oauth_parameters=t.passalong_params) oauth_request.sign() auth = oauth_request.to_header()["Authorization"] return auth
def signed_header_for_token(t): app = t.share.with_app try: activity = AppActivity.objects.get(name="main", app=app) except AppActivity.DoesNotExist: activity = AppActivity.objects.get(app=app) headers = {} app_index_req = utils.url_request_build(activity.url, "GET", headers, "") # sign as a two-legged OAuth request for the app oauth_request = OAuthRequest( consumer=app, token=None, # no access tokens: 2-legged request http_request=app_index_req, oauth_parameters=t.passalong_params) oauth_request.sign() auth = oauth_request.to_header()["Authorization"] return auth
def do_webhook(request, webhook_name): hook = None headers = {} # Find the preferred app for this webhook... try: hook = AppWebHook.objects.filter(name=webhook_name)[0] except: raise Exception("No hook exists with name: '%s'" % webhook_name) data = request.raw_post_data if (request.method == 'GET'): data = request.META['QUERY_STRING'] print "requesting web hook", hook.url, request.method, data hook_req = utils.url_request_build(hook.url, request.method, headers, data) # If the web hook needs patient context, we've got to generate + pass along tokens if (hook.requires_patient_context): app = hook.app record = request.principal.share.record account = request.principal.share.authorized_by # Create a new token for the webhook to access the in-context patient record token = HELPER_APP_SERVER.generate_and_preauthorize_access_token( app, record=record, account=account) # And supply the token details as part of the Authorization header, 2-legged signed # Using the helper app's consumer token + secret # (the 2nd parameter =None --> 2-legged OAuth request) oauth_request = OAuthRequest(app, None, hook_req, oauth_parameters=token.passalong_params) oauth_request.sign() for (hname, hval) in oauth_request.to_header().iteritems(): hook_req.headers[hname] = hval response = utils.url_request(hook.url, request.method, headers, data) print "GOT,", response return utils.x_domain( HttpResponse(response, mimetype='application/rdf+xml'))
def do_webhook(request, webhook_name): hook = None headers = {} # Find the preferred app for this webhook... try: hook = AppWebHook.objects.filter(name=webhook_name)[0] except: raise Exception("No hook exists with name: '%s'"%webhook_name) data = request.raw_post_data if (request.method == 'GET'): data = request.META['QUERY_STRING'] print "requesting web hook", hook.url, request.method, data hook_req = utils.url_request_build(hook.url, request.method, headers, data) # If the web hook needs patient context, we've got to generate + pass along tokens if (hook.requires_patient_context): app = hook.app record = request.principal.share.record account = request.principal.share.authorized_by # Create a new token for the webhook to access the in-context patient record token = HELPER_APP_SERVER.generate_and_preauthorize_access_token(app, record=record, account=account) # And supply the token details as part of the Authorization header, 2-legged signed # Using the helper app's consumer token + secret # (the 2nd parameter =None --> 2-legged OAuth request) oauth_request = OAuthRequest(app, None, hook_req, oauth_parameters=token.passalong_params) oauth_request.sign() for (hname, hval) in oauth_request.to_header().iteritems(): hook_req.headers[hname] = hval response = utils.url_request(hook.url, request.method, headers, data) print "GOT,", response return utils.x_domain(HttpResponse(response, mimetype='application/rdf+xml'))