处理Flutter中授权回调的查询参数

huangapple go评论107阅读模式
英文:

Handling query parameters in authorization callback on flutter

问题

I'm trying to use Spotify Web API with Flutter. I'm requesting for a user login from Spotify with openAuthorizationUrl() but it's returning a web page and I don't know how to handle it. I have to use this "code" parameter but I'm not even in the app. Here is the function:

  1. void openAuthorizationUrl() async {
  2. final clientId = 'cd3acd...7efbc';
  3. final redirectUri = 'https://localhost:8888/callback';
  4. final scope = 'user-read-private user-read-email user-top-read';
  5. final response_type = 'code';
  6. final authorizationUrl =
  7. 'https://accounts.spotify.com/authorize?response_type=$response_type&client_id=$clientId&scope=$scope&redirect_uri=$redirectUri';
  8. if (await canLaunchUrl(Uri.parse(authorizationUrl))) {
  9. var x = await launchUrl(Uri.parse(authorizationUrl));
  10. } else {
  11. throw 'Could not launch $authorizationUrl';
  12. }
  13. }

Here is the screenshot of the application:
处理Flutter中授权回调的查询参数

英文:

I'm trying to use Spotify Web API with Flutter. I'm requesting for a user login from Spotify with openAuthorizationUrl() but it's returning a web page and I don't know how to handle it. I have to use this "code" parameter but I'm not even in the app. Here is the function:

  1. void openAuthorizationUrl() async {
  2. final clientId = 'cd3acd...7efbc';
  3. final redirectUri = 'https://localhost:8888/callback';
  4. final scope = 'user-read-private user-read-email user-top-read';
  5. final response_type = 'code';
  6. final authorizationUrl =
  7. 'https://accounts.spotify.com/authorize?response_type=$response_type&client_id=$clientId&scope=$scope&redirect_uri=$redirectUri';
  8. if (await canLaunchUrl(Uri.parse(authorizationUrl))) {
  9. var x = await launchUrl(Uri.parse(authorizationUrl));
  10. } else {
  11. throw 'Could not launch $authorizationUrl';
  12. }
  13. }

Here is the screenshot of aplication:
处理Flutter中授权回调的查询参数

答案1

得分: 0

我将URL方案从http更改为我的应用程序名称,例如“com.example.myapp://localhost:8888/callback/”,并使用了flutter_web_auth2包。 http方案并不总是始终将重定向到应用程序,所以。

英文:

I changed url scheme http to my app's name like "com.example.myapp://localhost:8888/callback/" and I used flutter_web_auth2 package. http scheme is not redirecting to application all the time, so.

huangapple
  • 本文由 发表于 2023年5月22日 04:03:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76301710.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定