How to OAuth 2.0 login using Chrome custom tabs (Fitbit API)

不问归期 提交于 2019-12-04 08:31:14

问题


Fitbit API doesn't support webview anymore.

So, I studied chrome custom tabs and applied in my app.

But after login, when I pressed this pink button(allow button), nothing happened.(Image below)

How can I receive access token and store it in app?

Please help me.

Thanks.


回答1:


When authorizing agains the Fitbit API, you need to provide a redirect_uri, which is where the user will be taken after logging in. You need to provide a uri that will take the user back to your application.

To achieve that, create an intent filter and add a data tag with a custom scheme, such as myapplication://logincallback to the Activity you want to handle the login.

The intent filter will look something like this:

<intent-filter . . . >
    <data android:scheme="myapplication" android:host="logincallback" />
    . . .
</intent-filter>

Now, set the redirect_uri as mypplication://logincallback to the authorization step of the flow, and when the user clicks the pink button, it should open the Activity you added the intent filter.

You will be able to retrieve the parameters inside your activity by calling getData on the Intent.




回答2:


<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:host="logincallback"
                android:pathPattern=".*"
                android:scheme="myapp" />
        </intent-filter>

Suppose you have redirect_uri myapp://logincallback, then add above code in your activity in Manifest xml file and it will work.



来源:https://stackoverflow.com/questions/33772515/how-to-oauth-2-0-login-using-chrome-custom-tabs-fitbit-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!