How can I know which Terra user ID was authenticated by the widget?
AllSafeAardwolf25 months ago
After a user is authenticated using the Terra widget, an auth_success payload is sent to our webhook with a user_id. How would I get this user ID in the front end where the user gets redirected to after successful connection. What is the ideal flow here?
Danieladmin25 months ago
When Terra redirects to your site or app, post-auth success, we store the user_id and reference_id in the query parameters of the redirect, so you can get the user_id in sync from the current url (Terra redirects also support deep links and the query paramets should still be accessible)
Alternatively, you can set a reference_id when generating the widget which will also be sent with the auth_success payload and every following payload.
SafeAardwolf25 months ago
Understood, what would be the ideal authentication flow
Danieladmin25 months ago
The ideal authentication flow using the Terra API would look something like this:
- The user clicks on Connect Device in your app
- Your frontend requests your backend for a widget URL
- Your backend generates a widget url by calling the /auth/generateWidgetSession endpoint. This should be done in the backend as it requires your private API key. Provide a
auth_success_redirect_url, something likehttps://yourapp.com/terra/on_connection_success. You should also supply areference_id, potetially your internal user-id format e.g USR1234. - Redirect to the widget url in your frontend (or if you are developing a mobile app, open the url in the in-app browser)
- After the user connects their wearable fitness device, the widget will redirect to the
auth_success_redirect_urlyou provided with the query parameters:https://yourapp.com/terra/on_connection_success?user_id=123-abced-456&reference_id=USR1234 - Then if you wish to fetch an activity for this user, use the
user_idto make a GET request