def test_get_audience(self): self.assertEqual(get_audience('http://localhost/'), 'http://localhost:80') self.assertEqual(get_audience('https://localhost:443/'), 'https://localhost:443') self.assertEqual(get_audience('https://localhost/foo'), 'https://localhost:443') self.assertRaises(ValueError, get_audience, 'foo://localhost')
def persona_login(request): if request.method != 'POST': return HTTPMethodNotAllowed('Only POST is allowed') assertion = request.POST.get('assertion', None) if assertion is None: return HTTPBadRequest('The assertion parameter is required') if 'next_url' in request.params and request.params['next_url']: request.session['next_url'] = request.params['next_url'] settings = request.registry.settings data = { 'assertion': assertion, 'audience': get_audience(settings['public_url_root']) } response = requests.post(settings['persona_verifier_url'], data=data, verify=True) if response.ok: verification_data = response.json() if verification_data['status'] == 'okay': email = verification_data['email'] info = {'email': email} user_id = hashlib.sha1(email.encode('utf-8')).hexdigest() return register_or_update(request, 'persona', user_id, info, request.route_path('home')) else: return HTTPForbidden( 'Mozilla Persona verifier can not verify your identity') else: return HTTPBadGateway( 'Mozilla Persona verifier is not working properly')
def persona_login(request): if request.method != 'POST': return HTTPMethodNotAllowed('Only POST is allowed') assertion = request.POST.get('assertion', None) if assertion is None: return HTTPBadRequest('The assertion parameter is required') if 'next_url' in request.params and request.params['next_url']: request.session['next_url'] = request.params['next_url'] settings = request.registry.settings data = {'assertion': assertion, 'audience': get_audience(settings['public_url_root'])} response = requests.post(settings['persona_verifier_url'], data=data, verify=True) if response.ok: verification_data = response.json if verification_data['status'] == 'okay': email = verification_data['email'] info = {'email': email} user_id = hashlib.sha1(email.encode('utf-8')).hexdigest() return register_or_update(request, 'persona', user_id, info, request.route_path('home')) else: return HTTPForbidden('Mozilla Persona verifier can not verify your identity') else: return HTTPServerError('Mozilla Persona verifier is not working properly')
def persona_login(request): if request.method != "POST": return HTTPMethodNotAllowed("Only POST is allowed") assertion = request.POST.get("assertion", None) if assertion is None: return HTTPBadRequest("The assertion parameter is required") if "next_url" in request.params and request.params["next_url"]: request.session["next_url"] = request.params["next_url"] settings = request.registry.settings data = {"assertion": assertion, "audience": get_audience(settings["public_url_root"])} response = requests.post(settings["persona_verifier_url"], data=data, verify=True) if response.ok: verification_data = response.json() if verification_data["status"] == "okay": email = verification_data["email"] info = {"email": email} user_id = hashlib.sha1(email.encode("utf-8")).hexdigest() return register_or_update(request, "persona", user_id, info, request.route_path("home")) else: return HTTPForbidden("Mozilla Persona verifier can not verify your identity") else: return HTTPServerError("Mozilla Persona verifier is not working properly")