I am trying to access the fitbit API through oAuth on react-native. User login via fitbit works and after this, localhost is redirected and the access token is shown within the endpoint on the browser.
The issue i am facing currently is how can i get this access token from the browser in order to start fetching data from the fitbit api using the users access token within an android react-native application?
I am currently generating the oauth url and allowing the user to login. The issue is that after login is successful, there is no way i can retrieve the access token.
function OAuth(client_id, cb) {
const oauthurl = `https://www.fitbit.com/oauth2/authorize?${qs.stringify({
client_id,
response_type: "token",
scope: "heartrate activity activity profile sleep",
redirect_uri: "http://localhost",
expires_in: "31536000",
})}`;
console.log(oauthurl);
// Linking.openURL(oauthurl).catch((err) =>
// console.error("Error processing linking", err)
// );
}
After login is successful, this is the url i get back in the browser which contains the access token:
http://localhost/#access_token=eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIyM0JCSzUiLCJzdWIiOiI5TEJSUEMiLCJpc3MiOiJGaXRiaXQiLCJ0eXAiOiJhY2Nlc3NfdG9rZW4i2IK2F0fX1UuuIwZDbc4&user_id=9LBRPC&scope=sleep+heartrate+profile+activity&token_type=Bearer&expires_in=31534747
As mentioned previously, how can i get this access token back into my application to be used?