I’m working on Twitch OAuth integration in my Android app using Retrofit. I have this API call setup:
@GET("/oauth2/authorize?client_id=myClientId&scope=user:read:email&redirect_uri=http://localhost&response_type=token")
fun fetchAuthToken(): Call<ResponseBody>
When I launch the authorization flow using an Intent, the webview keeps refreshing and generating new access tokens continuously:
val authIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://id.twitch.tv/oauth2/authorize?client_id=myClientId&scope=user:read:email&redirect_uri=http://localhost&response_type=token"))
startActivity(authIntent)
The problem is that instead of getting one token and closing the webview, it keeps updating every second. My logcat shows tons of different tokens being generated. The back button doesn’t work either because the page keeps refreshing.
Here’s my manifest configuration:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity android:name=".activities.HomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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="localhost"
android:scheme="http"/>
</intent-filter>
</activity>
</application>
How can I capture the access token once and immediately close the webview to prevent this continuous token generation?