Skip to content

Instantly share code, notes, and snippets.

@full-of-foo
Last active August 29, 2015 14:27
Show Gist options
  • Save full-of-foo/8084527abd278a524969 to your computer and use it in GitHub Desktop.
Save full-of-foo/8084527abd278a524969 to your computer and use it in GitHub Desktop.
def assert_valid_persona_request():
"""Send the assertion to Mozilla's verifier service"""
assertion_key = flask.request.headers.get("PERSONA_ASSERTION")
if assertion_key is None:
raise PersonaAuthenticationError()
audience = flask.request.headers.get("Origin", None)
if audience is None:
audience = flask.request.url_root
assertion = {"assertion": assertion_key, "audience": audience}
resp = requests.post("https://verifier.login.persona.org/verify", data=assertion, verify=True)
if not resp.ok or resp.json().get('status') != "okay":
raise PersonaAuthenticationError()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment