我需要在使用 Spotify api 的 Flutter 应用程序中对用户进行身份验证。
我使用 flutter_web_auth 打开 WebView 并让用户在那里登录。
我无法返回应用程序。
在 Spotify 仪表板中,我将回调 Uri 设置为:https://spotifydata.com/callback 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 上的其他答案,但它们似乎不起作用。
正如中提到的Spotify 的 API 文档 https://developer.spotify.com/documentation/general/guides/authorization-guide/,身份验证将用户重定向到定义的redirect_uri
请求成功后。正在尝试登录https://spotifydata.com/ https://spotifydata.com/,它的redirect_uri设置为redirect_uri=https%3A%2F%2Fspotifydata.com%2Fsongdata
。确保定义的redirect_uri与清单文件中配置的回调方案匹配,因为这使应用程序能够通过意图过滤器处理重定向URL。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)