Skip to content

Instantly share code, notes, and snippets.

View alexastrum's full-sized avatar

Alex Astrum alexastrum

View GitHub Profile
<template>
<q-page class="row items-center justify-evenly">
<q-btn color="primary" @click="signIn">Sign in</q-btn>
<q-input v-model="status" label="Status" />
<q-btn color="primary" @click="saveStatus(loggedInUserName, status, avatarUrl)">Save status</q-btn>
<q-card v-for="(val, index) in statuses" :key="index">
<q-card-section>
<q-item-section avatar v-if="val.avatarUrl">
@override
void initState() {
deepLinkSubscription = getLinksStream().listen((String link) {
loginWithGitHub(link);
}, cancelOnError: true);
super.initState();
}
//...
String host = String(FUNCTIONS_REGION) + "-" + String(PROJECT_ID) + ".cloudfunctions.net";
HttpClient httpClient = HttpClient(wifiClient, host, 443);
httpClient.post("/getIdToken", "text/plain", deviceToken);
ECCX08.begin();
String deviceToken = ECCX08JWS.sign(/* slot */ 0, header, payload);
res.send({
nonce: await getNextNonce(device),
idToken,
});
const customToken = await admin
.auth()
.createCustomToken(device.data.uid, { deviceId: device.id });
const idTokenResponse = await axios.post<SignInWithCustomTokenResponse>(
"https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=" +
WEBAPP_APIKEY,
{ token: customToken, returnSecureToken: true }
);
const idToken = idTokenResponse.data.idToken;
if (!device.data.uid) {
res.send({
message: "Unclaimed device!",
});
}
const payloadNonce = Number(JSON.parse(payload).nonce);
const nonce = device.data.nonce;
if (payloadNonce !== nonce) {
res.send({
message: "Invalid nonce!",
});
}
const alg = "ES256";
const verifyResult = verify(
deviceToken,
alg,
device.data.publicKey
);
if (!verifyResult || header.alg !== alg) {
res.send({
message: "Invalid JWT!",
});
const deviceToken = req.body;
const { header, payload } = decode(deviceToken);
const device = header.kid && (await getDevice(header.kid));
if (!device) {
res.send({
message: "Unknown device!",
});
}