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

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more