Published
Edited
Feb 4, 2022
Importers
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function password_authorization_endpoint({
me, // function that returns a string or a string
secret // Encrypted empty payload protected by password generated in @endpointservices/notebook-secret
}) {
return deploy("password_authorization_endpoint", async (req, res) => {
const params = decodeJsonOrForm(req.body);
if (req.method === 'GET') {
res.send(`
<form action="" method="post">
<label for="fcode">Password</label>
<input type="password" id="fcode" name="password"><br><br>
<input type="hidden" name="state" value="${req.query.state}">
<input type="hidden" name="redirect_uri" value="${req.query.redirect_uri}">
<input type="submit" value="Submit">
</form>
`)
} else if (req.method === 'POST' && params.password) {
try {
await decode(params.password, secret);
const code = randomId(16);
await firebase.database().ref(
`@endpointservices/password_authorization_endpoint/${code}`
).set({
me: typeof me === 'function' ? me() : me,
timestamp: {".sv": "timestamp"}
})
res.redirect(`${req.query.redirect_uri}?code=${code}&state=${req.query.state}`)
} catch (err) {
res.status(403).send(`Incorrect password: ` + err.message)
}
} else if (req.method === 'POST' && params.code) {
const payload = (await firebase.database().ref(
`@endpointservices/password_authorization_endpoint/${params.code}`
).once('value')).val()
res.json({
"me": payload.me
});
} else {
res.status(400).send(`Unknown request method ${req.method}`)
}
}, {
modifiers: ['terminal']
});
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more