【问题标题】:Flutter - oauth2 - Android - redirecturi not workingFlutter - oauth2 - Android - redirecturi 不工作
【发布时间】:2021-09-26 17:06:07
【问题描述】:

我对 Android 上的颤振实现有疑问。在 iOS 上它工作正常。 这是我的 AndroidManifest.xml:

<intent-filter android:label="flutter_web_auth">
   <action android:name="android.intent.action.VIEW" />
   <category android:name="android.intent.category.DEFAULT" />
   <category android:name="android.intent.category.BROWSABLE" />
   <data android:scheme="com.mycomp.myapp"/>
</intent-filter>

我这样定义了 SpotifyClient:

class SpotifyOAuth2Client extends OAuth2Client {
    SpotifyOAuth2Client({required String redirectUri, required String customUriScheme}) :
            super(
                authorizeUrl: 'https://accounts.spotify.com/authorize',
                tokenUrl: 'https://accounts.spotify.com/api/token',
                redirectUri: redirectUri,
                customUriScheme: customUriScheme) {
        this.accessTokenRequestHeaders = {'Accept': 'application/json'};
    }
}

这里是我尝试给客户打电话的地方:

OAuth2Client client = SpotifyOAuth2Client(
            redirectUri: 'com.mycomp.myapp://callback',
            customUriScheme: 'com.mycomp.myapp');
var authResp = await client.requestAuthorization(
            clientId: 'huhuhuhuhuhuhuhuhu',
            customParams: {'show_dialog': 'true'},
            scopes: ['user-read-private', 'user-read-playback-state', 'user-modify-playback-state', 'user-read-currently-playing', 'user-read-email']);

print(authResp.code);

应用正确触发了对 Spotify 的授权。我可以在网络浏览器上登录并接受。 然后我被重定向到 myApp 但没有任何反应。上面的 print(authResp.code)(当然还有后面的所有内容)永远不会触发。

同样,在 iOS 上我没有问题。

我尝试了很多事情,但没有成功。任何帮助将不胜感激!

【问题讨论】:

    标签: android flutter oauth-2.0


    【解决方案1】:

    经过多次试验,我已经能够解决这个问题。 希望它可以帮助其他人。

    添加以下活动(而不仅仅是在现有活动中的意图过滤器)取得了成功:

    <activity android:name="com.linusu.flutter_web_auth.CallbackActivity" >
      <intent-filter android:label="flutter_web_auth">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="com.mycomp.myapp" android:host="callback" />
      </intent-filter>
    </activity>
    

    【讨论】:

      猜你喜欢
      • 2022-07-24
      • 2021-03-03
      • 1970-01-01
      • 2021-03-29
      • 2020-05-17
      • 2021-08-19
      • 2021-06-12
      • 1970-01-01
      • 2023-02-05
      相关资源
      最近更新 更多