-
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 all 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,9 @@ | ||
| # 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: [Optional] SID of the service created in Twilio verify | ||
| # format: sid | ||
| # required: false | ||
| ANDROID_APP_KEYS= | ||
| 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 |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| "private": true, | ||
| "dependencies": { | ||
| "twilio": "^5.3.3", | ||
| "axios": "^1.7.7" | ||
| "axios": "^1.7.7", | ||
| "uuid": "^11.0.4" | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
Should this be
true?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.
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