slides initially by Dan Callahan
<script src="https://login.persona.org/include.js"></script>
$('#loginBtn').click( function () { navigator.id.request() } );
$('#logoutBtn').click( function () { navigator.id.logout() } );
navigator.id.watch({
});
navigator.id.watch({
loggedInUser: ...,
onlogin: function (assertion) {
},
onlogout: function () {
}
});
navigator.id.watch({
loggedInUser: "alice@example.com",
onlogin: function (assertion) {
},
onlogout: function () {
}
});
navigator.id.watch({
loggedInUser: "bob@foobar.test",
onlogin: function (assertion) {
},
onlogout: function () {
}
});
navigator.id.watch({
loggedInUser: null,
onlogin: function (assertion) {
},
onlogout: function () {
}
});
navigator.id.watch({
loggedInUser: null,
onlogin: function (assertion) {
// A user wants to log in! Send the assertion to my backend.
},
onlogout: function () {
}
});
navigator.id.watch({
loggedInUser: null,
onlogin: function (assertion) {
// A user wants to log in! Send the assertion to my backend.
$.post("/login", {"assertion": assertion})
},
onlogout: function () {
}
});
navigator.id.watch({
loggedInUser: null,
onlogin: function (assertion) {
// A user wants to log in! Send the assertion to my backend.
$.post("/login", {"assertion": assertion})
.done(function () { window.location.reload() })
},
onlogout: function () {
}
});
navigator.id.watch({
loggedInUser: null,
onlogin: function (assertion) {
// A user wants to log in! Send the assertion to my backend.
$.post("/login", {"assertion": assertion})
.done(function () { window.location.reload() })
.fail(function () { navigator.id.logout() });
},
onlogout: function () {
}
});
navigator.id.watch({
loggedInUser: null,
onlogin: function (assertion) {
// A user wants to log in! Send the assertion to my backend.
$.post("/login", {"assertion": assertion})
.done(function () { window.location.reload() })
.fail(function () { navigator.id.logout() });
},
onlogout: function () {
// A user has logged out! Tear down their session.
}
});
navigator.id.watch({
loggedInUser: null,
onlogin: function (assertion) {
// A user wants to log in! Send the assertion to my backend.
$.post("/login", {"assertion": assertion})
.done(function () { window.location.reload() })
.fail(function () { navigator.id.logout() });
},
onlogout: function () {
// A user has logged out! Tear down their session.
$.post("/logout")
}
});
navigator.id.watch({
loggedInUser: null,
onlogin: function (assertion) {
// A user wants to log in! Send the assertion to my backend.
$.post("/login", {"assertion": assertion})
.done(function () { window.location.reload() })
.fail(function () { navigator.id.logout() });
},
onlogout: function () {
// A user has logged out! Tear down their session.
$.post("/logout")
.always(function () { window.location.reload() });
}
});
navigator.id.watch({
loggedInUser: null,
onlogin: function (assertion) {
// A user wants to log in! Send the assertion to my backend.
$.post("/login", {"assertion": assertion})
.done(function () { window.location.reload() })
.fail(function () { navigator.id.logout() });
},
onlogout: function () {
// A user has logged out! Tear down their session.
$.post("/logout")
.always(function () { window.location.reload() });
}
});
@app.route("/logout", methods=["POST"])
def logout():
session.clear()
return Response(status=204)
@app.route("/login", methods=["POST"])
def login():
@app.route("/login", methods=["POST"])
def login():
# Send the assertion to Mozilla's verifier service
@app.route("/login", methods=["POST"])
def login():
# Send the assertion to Mozilla's verifier service
data = {"assertion": request.form["assertion"],
"audience": "https://example.com:443"}
@app.route("/login", methods=["POST"])
def login():
# Send the assertion to Mozilla's verifier service
data = {"assertion": request.form["assertion"],
"audience": "https://example.com:443"}
resp = post("https://verifier.login.persona.org/verify",
data=data)
@app.route("/login", methods=["POST"])
def login():
# Send the assertion to Mozilla's verifier service
data = {"assertion": request.form["assertion"],
"audience": "https://example.com:443"}
resp = post("https://verifier.login.persona.org/verify",
data=data)
info = resp.json()
{
"status": "okay",
"email": "bob@foobar.test",
"audience": "https://example.com:443",
"expires": 1308859352261,
"issuer": "foobar.test"
}
@app.route("/login", methods=["POST"])
def login():
# Send the assertion to Mozilla's verifier service
data = {"assertion": request.form["assertion"],
"audience": "https://example.com:443"}
resp = post("https://verifier.login.persona.org/verify",
data=data)
info = resp.json()
@app.route("/login", methods=["POST"])
def login():
# Send the assertion to Mozilla's verifier service
data = {"assertion": request.form["assertion"],
"audience": "https://example.com:443"}
resp = post("https://verifier.login.persona.org/verify",
data=data)
info = resp.json()
if info["status"] != "okay":
abort(403)
@app.route("/login", methods=["POST"])
def login():
# Send the assertion to Mozilla's verifier service
data = {"assertion": request.form["assertion"],
"audience": "https://example.com:443"}
resp = post("https://verifier.login.persona.org/verify",
data=data)
info = resp.json()
if info["status"] != "okay":
abort(403)
session["email"] = info["email"]
return Response(status=204)