Created
January 20, 2022 11:49
-
-
Save BryanPinsker/308738bf37ce407b90dfd24974a6ad07 to your computer and use it in GitHub Desktop.
Widget authentication code examples
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
window.AnswersWidget.onLoaded(() => { | |
window.AnswersWidget.addAuthenticationFn(() => { | |
// This request should include your own method of authentication (e.g. cookie, Authorization header) | |
return axios.get(`${YOUR_SERVER_URL}/auth-token`).then((response) => response.data); | |
}); | |
}); |
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
// This example uses express and axios | |
// Add a route like the following to your express routes | |
app.get('/auth-token', async function(req, res, next) { | |
const YOUR_ANSWERS_SUBDOMAIN = 'write your answers subdomain'; | |
const dto = { | |
keyId: 'Your Wix Answers API key', | |
secret: 'Your Wix Answers API secret', | |
widgetId: 'your widget id', | |
// You should verify the users identity and get their email and name using your own method of authentication | |
email: 'usersemail@example.com', | |
emailVerified: true, // Boolean, indicate if the authenticated user's email is verified or not. | |
firstName: 'The users first name', // optional | |
lastName: 'The users last name', // optional | |
}; | |
const requestUrl = `https://${YOUR_ANSWERS_SUBDOMAIN}.wixanswers.com/api/v1/widgets/${dto.widgetId}/auth`; | |
const token = await axios.post(requestUrl, dto).then((res) => { | |
return res.data.token; | |
}); | |
res.send(token); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment