小编Bur*_*lin的帖子

如果应用已获得授权,则Android Chrome自定义标签/ Fitbit网络API不会重定向.(OAuth2.0的)

我打算为警报同步创建第三方fitbit应用程序.

但是,我在注册我的应用程序时遇到了一些困难,即使您的客户端已经注册到应用程序,我也会更明确地获取访问令牌.(考虑用户重新安装其应用程序的情况).

我正在使用Chrome自定义标签(因为FitBit禁止使用WebView)来请求访问令牌:

String url = "https://www.fitbit.com/oauth2/authorize?" +
                    "response_type=token" +
                    "&client_id=XXXXXX" +
                    "&scope=activity"+
                    "&redirect_uri=fitbittester://logincallback";
            customTabsIntent.launchUrl(MainActivity.this, Uri.parse(url));
Run Code Online (Sandbox Code Playgroud)

在重定向到使用intent-filter定义的自定义方案时:

<activity
        android:name=".TestActivity"
        android:label="TestActivity"
        android:theme="@style/AppTheme.NoActionBar">
        <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="fitbittester" android:host="logincallback" />
        </intent-filter>
    </activity>
Run Code Online (Sandbox Code Playgroud)

应该启动TestActivity,我将从给定的Intent获取我的AccessToken:

public class TestActivity extends AppCompatActivity {

String string;

@Override
protected void onNewIntent(Intent intent) {
    string = intent.getDataString();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    onNewIntent(getIntent());
    Toast.makeText(TestActivity.this, string , Toast.LENGTH_LONG).show();
    Log.e("TAG", string);
    Log.e("TAG", string.substring(string.indexOf("&access_token")+14));
}
Run Code Online (Sandbox Code Playgroud)

}

第一次运行时一切正常(提供客户端尚未获得授权的事实),但之后如果想再次获取我的访问令牌(我知道我应该在本地存储它 - …

android intentfilter oauth-2.0 fitbit chrome-custom-tabs

9
推荐指数
1
解决办法
3427
查看次数