-
Notifications
You must be signed in to change notification settings - Fork 345
chore(update): Update passkeys-backend to use verify instead of comms #607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
a1a072c
4b660de
0124449
bd92884
1326f38
a4145b4
9d24ea4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,14 @@ | ||
| # description: The URL of the API for passkeys | ||
| # format: url | ||
| # required: true | ||
| API_URL=https://comms.twilio.com/preview | ||
| API_URL=https://verify.twilio.com/v2/Services | ||
|
|
||
| # description: [Optional] Comma separated domains for Android application | ||
| # format: list(text) | ||
| # description: Namespace UUID for generating deterministic UUIDs with the uuid library | ||
| # format: text | ||
| # required: false | ||
| ANDROID_APP_KEYS= | ||
| NAMESPACE= | ||
|
|
||
| # description: [Optional] SID of the service created in Twilio verify | ||
| # format: sid | ||
| # required: false | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if I set this to true the code exchange will take it as a mandatory when creating the function, but this is created with one of the endpoints |
||
| SERVICE_SID= | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| const origins = (context) => { | ||
| const { DOMAIN_NAME } = context; | ||
| return [`https://${DOMAIN_NAME}`, 'android:apk-key-hash:{base64_hash}']; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this for Android & Web? What about iOS? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iOS only need the |
||
| }; | ||
|
|
||
| module.exports = { | ||
| origins, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| const assets = Runtime.getAssets(); | ||
| const { origins } = require(assets['/origins.js'].path); | ||
|
|
||
| exports.handler = function (context, event, callback) { | ||
| const response = new Twilio.Response(); | ||
| response.appendHeader('Content-Type', 'application/json'); | ||
|
|
||
| response.setBody({ origins: origins(context) }); | ||
|
|
||
| return callback(null, response); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,32 +2,32 @@ const axios = require('axios'); | |
|
|
||
| // eslint-disable-next-line consistent-return | ||
| exports.handler = async (context, _, callback) => { | ||
| const { DOMAIN_NAME, API_URL } = context; | ||
| const { API_URL, SERVICE_SID } = context; | ||
|
|
||
| const response = new Twilio.Response(); | ||
| response.appendHeader('Content-Type', 'application/json'); | ||
| response.appendHeader('Access-Control-Allow-Origin', '*'); | ||
| response.appendHeader('Access-Control-Allow-Methods', 'OPTIONS, POST, GET'); | ||
| response.appendHeader('Access-Control-Allow-Headers', 'Content-Type'); | ||
|
|
||
| const { username, password } = context.getTwilioClient(); | ||
|
|
||
| const requestBody = { | ||
| content: { | ||
| // eslint-disable-next-line camelcase | ||
| rp_id: DOMAIN_NAME, | ||
| }, | ||
| }; | ||
|
|
||
| const challengeURL = `${API_URL}/Verifications`; | ||
| const challengeURL = `${API_URL}/${SERVICE_SID}/Passkeys/Challenges`; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we have a sense of when these endpoints will be available in the Node Helper Library? |
||
|
|
||
| try { | ||
| const APIResponse = await axios.post(challengeURL, requestBody, { | ||
| auth: { | ||
| username, | ||
| password, | ||
| }, | ||
| }); | ||
| const APIResponse = await axios.post( | ||
| challengeURL, | ||
| {}, | ||
| { | ||
| auth: { | ||
| username, | ||
| password, | ||
| }, | ||
| } | ||
| ); | ||
|
|
||
| response.setStatusCode(200); | ||
| response.setBody(APIResponse.data.next_step); | ||
| response.setBody(APIResponse.data.options); | ||
| } catch (error) { | ||
| const statusCode = error.status || 400; | ||
| response.setStatusCode(statusCode); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| const axios = require('axios'); | ||
|
|
||
| const assets = Runtime.getAssets(); | ||
| const { origins } = require(assets['/origins.js'].path); | ||
|
|
||
| exports.handler = async function (context, event, callback) { | ||
| const { DOMAIN_NAME, API_URL } = context; | ||
|
|
||
| const response = new Twilio.Response(); | ||
| response.appendHeader('Content-Type', 'application/json'); | ||
| response.appendHeader('Access-Control-Allow-Origin', '*'); | ||
| response.appendHeader('Access-Control-Allow-Methods', 'OPTIONS, POST, GET'); | ||
| response.appendHeader('Access-Control-Allow-Headers', 'Content-Type'); | ||
|
|
||
| const { username, password } = context.getTwilioClient(); | ||
|
|
||
| const data = new URLSearchParams(); | ||
| data.append('FriendlyName', 'Passkeys Sample Backend'); | ||
| data.append('Passkeys.RelyingParty.Id', DOMAIN_NAME); | ||
| data.append('Passkeys.RelyingParty.Name', 'Passkeys Sample Backend'); | ||
| data.append('Passkeys.RelyingParty.Origins', origins(context).join(',')); | ||
| data.append('Passkeys.AuthenticatorAttachment', 'platform'); | ||
| data.append('Passkeys.DiscoverableCredentials', 'preferred'); | ||
| data.append('Passkeys.UserVerification', 'preferred'); | ||
|
|
||
| const createServiceURL = `${API_URL}`; | ||
|
|
||
| try { | ||
| const APIResponse = await axios.post(createServiceURL, data, { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should already be available in the Node Helper Library - I vote we add that as an import instead of using axios. |
||
| headers: { | ||
| 'Content-Type': 'application/x-www-form-urlencoded', | ||
| }, | ||
| auth: { | ||
| username, | ||
| password, | ||
| }, | ||
| }); | ||
|
|
||
| response.setStatusCode(200); | ||
| response.setBody(APIResponse.data); | ||
| } catch (error) { | ||
| const statusCode = error.status || 400; | ||
| response.setStatusCode(statusCode); | ||
| response.setBody(error.message); | ||
| } | ||
|
|
||
| return callback(null, response); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,17 @@ | ||
| const axios = require('axios'); | ||
| const { v5 } = require('uuid'); | ||
|
|
||
| const assets = Runtime.getAssets(); | ||
| const { detectMissingParams } = require(assets['/services/helpers.js'].path); | ||
|
|
||
| exports.handler = async (context, event, callback) => { | ||
| const { DOMAIN_NAME, API_URL, ANDROID_APP_KEYS } = context; | ||
| const { API_URL, SERVICE_SID, NAMESPACE } = context; | ||
|
||
|
|
||
| const response = new Twilio.Response(); | ||
| response.appendHeader('Content-Type', 'application/json'); | ||
| response.appendHeader('Access-Control-Allow-Origin', '*'); | ||
| response.appendHeader('Access-Control-Allow-Methods', 'OPTIONS, POST, GET'); | ||
| response.appendHeader('Access-Control-Allow-Headers', 'Content-Type'); | ||
|
|
||
| // Verify request comes with username | ||
| const missingParams = detectMissingParams(['username'], event); | ||
|
|
@@ -22,40 +26,21 @@ exports.handler = async (context, event, callback) => { | |
|
|
||
| const { username, password } = context.getTwilioClient(); | ||
|
|
||
| const androidOrigins = (keys) => { | ||
| if (!keys || keys.trim() === '""') return []; | ||
| return keys.split(','); | ||
| }; | ||
| const uuidIdentity = v5(event.username, NAMESPACE); | ||
|
||
|
|
||
| // Request body sent to passkeys verify URL call | ||
| /* eslint-disable camelcase */ | ||
| const requestBody = { | ||
| friendly_name: 'Passkey Example', | ||
| to: { | ||
| user_identifier: event.username, | ||
| }, | ||
| content: { | ||
| relying_party: { | ||
| id: DOMAIN_NAME, | ||
| name: 'PasskeySample', | ||
| origins: [ | ||
| `https://${DOMAIN_NAME}`, | ||
| ...androidOrigins(ANDROID_APP_KEYS), | ||
| ], | ||
| }, | ||
| user: { | ||
| display_name: event.username, | ||
| }, | ||
| authenticator_criteria: { | ||
| authenticator_attachment: 'platform', | ||
| discoverable_credentials: 'preferred', | ||
| user_verification: 'preferred', | ||
| }, | ||
| friendly_name: event.username, | ||
| identity: uuidIdentity, | ||
| config: { | ||
| authenticator_attachment: 'platform', | ||
| discoverable_credentials: 'preferred', | ||
| user_verification: 'preferred', | ||
| }, | ||
| }; | ||
|
|
||
| // Factor URL of the passkeys service | ||
| const factorURL = `${API_URL}/Factors`; | ||
| const factorURL = `${API_URL}/${SERVICE_SID}/Passkeys/Factors`; | ||
|
|
||
| // Call made to the passkeys service | ||
| try { | ||
|
|
@@ -67,9 +52,11 @@ exports.handler = async (context, event, callback) => { | |
| }); | ||
|
|
||
| response.setStatusCode(200); | ||
| response.setBody(APIResponse.data.next_step); | ||
| response.setBody({ | ||
| ...APIResponse.data.options.publicKey, | ||
| identity: uuidIdentity, | ||
| }); | ||
| } catch (error) { | ||
| console.error('Error in passkeys registration start:', error.message); | ||
| const statusCode = error.status || 400; | ||
| response.setStatusCode(statusCode); | ||
| response.setBody(error.message); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| "private": true, | ||
| "dependencies": { | ||
| "twilio": "^5.3.3", | ||
| "axios": "^1.7.7" | ||
| "axios": "^1.7.7", | ||
| "uuid": "^11.0.4" | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this value? What will be the format of the value? Could there be a default value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose is to create a uuid based on the username, this is described in the readme, I think the UUID as is described is self explanatory, but yes we can add a default value