Created
February 17, 2022 19:38
-
-
Save AdamJLemmon/e7c236e2576847f638088ff5fea852ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (org.settings && org.settings.mobileWalletEnabled) { | |
const login_hint = uuid(); | |
const credentialId = cert.id; | |
const loginHint = { | |
credentialId, | |
login_hint, | |
credentialType: OIDC_DEFAULT_CREDENTIAL_TYPE, | |
expiry: Date.now() + OIDC_DOES_NOT_EXPIRE_TTL, // no expiry for now... | |
purpose: OIDC_LOGIN_HINT_CREDENTIAL_ISSUANCE_PURPOSE, | |
multiUse: true, // allow these to be picked up mutliple times for now | |
}; | |
const loginHintInsertRes = await db.conn.collection(OIDC_LOGIN_HINTS_COLLECTION) | |
.insertOne(loginHint); | |
// If successful then build the Mobile URL | |
if (loginHintInsertRes.insertedCount === 1) { | |
// This is a third party initiated login | |
const iss = `${API_URL}/oidc/auth`; | |
const query = encodeURIComponent(`iss=${iss}&login_hint=${login_hint}`); | |
/** | |
* @TODO - need to define MOBILE_URL but the mobile wallet will just parse iss and login_hint anyways | |
*/ | |
mobileUrl = `${MOBILE_WALLET_INIT_LOGIN_URL}?${query}`; | |
/** | |
* @NOTE - pattern that was used before to get the QR code into an html email emplate... | |
* perhaps sendgrid templates have an option to encode url as qr code...? | |
*/ | |
// Set the initiate login QR code as an option to download to a separate device | |
const downloadQrCode = await qrcode.toDataURL(mobileUrl); | |
// just want the data need to get rid of the data url prefix | |
const base64Data = downloadQrCode.split(',')[1]; | |
const Body = Buffer.from(base64Data, 'base64'); | |
const env = DEPLOYED_ENV || 'temp'; | |
const Key = `download-qr-codes/${env}/${cert.id}.png`; | |
const Bucket = AWS_TRYBE_PUBLIC_ASSETS_BUCKETS; | |
const { | |
Location, | |
} = await aws.uploadObject({ | |
Bucket, | |
Body, | |
Key, | |
ACL: 'public-read', | |
}); | |
downloadUrl = Location; | |
} | |
} | |
/** | |
* @TODO - proceed to execute ending the email but will need to use a template that support the mobile app as well | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment