我需要在我的Flutter应用程序中验证用户,它使用Spotify api。我使用flutter_web_auth打开WebView并让用户在那里登录。我无法返回到应用程序。
在Spotify Dashboard中,我将回调Uri设置为:https://spotifydata.com/callback
final callbackUrl = "https://spotifydata.com/callback";
void _authenticateSpotfy() async {
final url = Uri.https('accounts.spotify.com', '/authorize', {
'response_type': 'code',
'client_id': clientID,
'redirect_uri': 'https://spotifydata.com/callback:/',
'scope': 'user-read-private user-read-email',
});
final result = await FlutterWebAuth.authenticate(
url: url.toString(), callbackUrlScheme: callbackUrl);
}AndroidManifest.xml
<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="https://spotifydata.com/callback" />
</intent-filter>
</activity>我在Stack上尝试过其他答案,但它们似乎不起作用。
发布于 2021-08-03 14:19:54
正如Spotify's API docs中提到的,在成功请求时,身份验证会将用户重定向到定义的redirect_uri。尝试登录https://spotifydata.com/时,已将redirect_uri设置为redirect_uri=https%3A%2F%2Fspotifydata.com%2Fsongdata。确保定义的redirect_uri与清单文件中配置的回调方案匹配,因为这使应用程序能够通过intent-filter处理重定向URL。
https://stackoverflow.com/questions/60554240
复制相似问题