Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Authentication URI redirect error, however everything still works?

So a bit of a weird problem, and sorry if this is obvious but I'm quite new to working with OAuth and Android.
I am building a Fitbit android app. My callback url is myapp://authorized in the fitbit dev settings.

In the android manifest I have code that opens up my application whenever myapp://authorized is called:

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" android:host="authorized" />
</intent-filter>

 So far so good. This is the code that handles extracting the access token:

 

 

public void authorize(View view) {
String url = "https://www.fitbit.com/oauth2/authorize?response_type=token&client_id=22874H&redirect_uri=myapp%3A%2F%2Fauthorized%2F&scope=activity%20nutrition%20heartrate%20location%20nutrition%20profile%20settings%20sleep%20social%20weight"; CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.launchUrl(this, Uri.parse(url)); Intent intent = getIntent(); if (Intent.ACTION_VIEW.equals(intent.getAction())) { Uri data = getIntent().getData(); String token = data.getEncodedFragment(); Log.e("Full URL", data.toString()); Log.e("Token", token); } }

The problem is that when the CustomTabs opens up the fitbit site and I enter my credentials, fitibit tells me I have an invalid redirect uri. BUT, my redirect uri seemingly is valid, as not only does it return to my application, but I actually receive the access token (Oddly I have to run the authorize method twice, the first time nothing happens).

This is what prints in the console after running twice:

01-02 01:08:53.083 19240-19240/jkstudios.gitfit2 E/Full URL: myapp://authorized/#access_token=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI1QjRZR1ciLCJhdWQiOiIyMjg3NEgiLCJpc3MiOiJGaXRiaXQiLCJ0eXAiOiJhY2Nlc3NfdG9rZW4iLCJzY29wZXMiOiJ3aHIgd251dCB3cHJvIHdzbGUgd3dlaSB3c29jIHdzZXQgd2FjdCB3bG9jIiwiZXhwIjoxNDgzNDE4MjY1LCJpYXQiOjE0ODMzMzczNTR9.3-YPw4zhP8ibOZa5jqUbcn7y2tnUCfJjYIMmOnFwgQ8&user_id=5B4YGW&scope=sleep+settings+nutrition+activity+social+heartrate+profile+weight+location&token_type=Bearer&expires_in=80911
01-02 01:08:53.084 19240-19240/jkstudios.gitfit2 E/Token: access_token=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI1QjRZR1ciLCJhdWQiOiIyMjg3NEgiLCJpc3MiOiJGaXRiaXQiLCJ0eXAiOiJhY2Nlc3NfdG9rZW4iLCJzY29wZXMiOiJ3aHIgd251dCB3cHJvIHdzbGUgd3dlaSB3c29jIHdzZXQgd2FjdCB3bG9jIiwiZXhwIjoxNDgzNDE4MjY1LCJpYXQiOjE0ODMzMzczNTR9.3-YPw4zhP8ibOZa5jqUbcn7y2tnUCfJjYIMmOnFwgQ8&user_id=5B4YGW&scope=sleep+settings+nutrition+activity+social+heartrate+profile+weight+location&token_type=Bearer&expires_in=80911

 

If anyone has a clue what's going on, I would be incredibly grateful, and thank

 

Best Answer
0 Votes
1 REPLY 1

Help,I also encountered this problem,did you find the solution,please!

Best Answer
0 Votes