Terra
Integrations
Research

Integration

API
Unified API
SDK
SDK
Authentication
Authentication
Streaming
Streaming
Blood
Blood Report API
Planned Workouts
Planned Workouts
AI Interface
AI Interface

User engagement

Graph API
Graph API
Scores
Health Scores
Rewards
Health Rewards

Use cases

Enterprise
Enterprise
Insurance
Insurance

Developers

Wearable Data
Wearable Data
Community
Community
Documentation
Documentation

Learn

Blog
Blog
Podcast
Podcast
Events
Events
Reports
Reports

Company

Customers
Customers
Careers
Careers
Partners
Partners
Support
Support
Pricing
Become an integrationGet started
IntegrationsResearch
Unified APIUnified APISDKSDKAuthenticationAuthenticationStreamingStreamingGraph APIGraph APIScoresScoresRewardsRewardsBlood Report APIBloodAI InterfaceAI Interface
EnterpriseEnterpriseInsuranceInsuranceWearable DataWearable DataCommunityCommunityDocumentationDocumentationBlogBlogPodcastPodcastEventsEventsReportsReportsCustomersCustomersCareersCareersPartnersPartnersSupportSupport
Pricing
Get startedBecome an integration


Cookie Preferences

Essential CookiesAlways On
Advertisement Cookies
Analytics Cookies

Crunch Time: Embrace the Cookie Monster Within!

We use cookies to enhance your browsing experience and analyse our traffic. By clicking “Accept All”, you consent to our use of cookies according to our Cookie Policy. You can change your mind any time by visiting out cookie policy.

Cookies Policy
zap

Latest

zap

Popular

API

Unified API

SDK

Phone SDK

Authentication

Widget

Streaming

Streaming

Graph API

Graph API

How can I know which Terra user ID was authenticated by the widget?

All

SafeAardwolf26 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?

terra

Danieladmin26 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.


SafeAardwolf26 months ago

Understood, what would be the ideal authentication flow


terra

Danieladmin26 months ago

The ideal authentication flow using the Terra API would look something like this:

  1. The user clicks on Connect Device in your app
  2. Your frontend requests your backend for a widget URL
  3. 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 like https://yourapp.com/terra/on_connection_success. You should also supply a reference_id, potetially your internal user-id format e.g USR1234.
  4. Redirect to the widget url in your frontend (or if you are developing a mobile app, open the url in the in-app browser)
  5. After the user connects their wearable fitness device, the widget will redirect to the auth_success_redirect_url you provided with the query parameters: https://yourapp.com/terra/on_connection_success?user_id=123-abced-456&reference_id=USR1234
  6. Then if you wish to fetch an activity for this user, use the user_id to make a GET request