Spotify API 颤振身份验证

时间:2021-01-09 04:28:24

标签: firebase flutter dart spotify

所以我试图将 Spotify 集成到我的应用程序中,但在成功登录后无法导航回我的音乐屏幕。我正在使用 flutter_web_auth 插件。我只是不确定如何接收访问令牌。我尝试使用 firebase 动态链接,这似乎很痛苦。但我能够复制和粘贴并查看 URL 中的访问令牌。我确信我可以通过这种方式达到预期的结果,但我不想这样做!!!我已经阅读了其他一些堆栈溢出的帖子,它们使它看起来更容易。这是我的 AndriodManifest.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="queursion://"/>
            </intent-filter>
            </activity>

这是我的用户验证码。它允许用户登录并拥有令牌,但永远不会重定向回我的应用程序,因此我可以解析令牌。 musicpagecontroller.dart

import 'package:flutter/services.dart';

import '../view/LoggedIn/Front _Pages/musicpage.dart';
import 'package:flutter_web_auth/flutter_web_auth.dart';

class MusicPageController {
  MusicPageState state;

  MusicPageController(this.state);

  void loginSpotify() async {
    const String clientId = "I have this exposed in my app deleted here though"
    const String redirectUri = "queursion://";
    const scopes = [
      'streaming',
    ];
    String uri = 'https://accounts.spotify.com/authorize';
    uri += '?client_id=$clientId';
    uri += '&redirect_uri=$redirectUri';
    uri += '&response_type=token';
    uri += '&scope=${scopes.join('+')}';
    
    print(uri);
  try {
//never returns back and prints ("hello")
  final result = await FlutterWebAuth.authenticate(url: uri.toString(), callbackUrlScheme:redirectUri);
  print("hello");
  final token = Uri.parse(result).queryParameters['token'];
 
  }  on Exception catch (e) {
    print(e.toString());
    }

补充一下,我去了 Spotify 的仪表板,并将“queursion://”作为重定向 URIS 之一

0 个答案:

没有答案