ThexXTURBOXx / flutter_web_auth_2

Flutter plugin for authenticating a user with a web service
https://pub.dev/packages/flutter_web_auth_2
MIT License
51 stars 50 forks source link

Help! I want to use flutter_web_auth_2 for web app #34

Closed xjeremy60 closed 1 year ago

xjeremy60 commented 1 year ago

Hello,

I want to use flutter_web_auth_2 for web app.

I test my application with visual studio code.

I have this error : flutter: Invalid argument(s): Callback url scheme must start with http://localhost:{port}

This is my code :

import 'package:flutter/material.dart';
import 'package:flutter_web_auth_2/flutter_web_auth_2.dart';

class HomeController {
  final String pageTitle = 'Jukebox';
  final String clientId =
      'YOUR_CLIENT_ID'; // Remplacez par votre client ID Spotify
  final String redirectUri =
      'http://localhost:8080'; // Remplacez par votre URL de redirection Spotify

  Future<void> handleConnectToSpotify(BuildContext context) async {
    const authorizationEndpoint = 'https://accounts.spotify.com/authorize';
    const responseType = 'token';
    const scope =
        'user-read-private user-read-email'; // Définissez les scopes que vous souhaitez utiliser
    final authUrl =
        '$authorizationEndpoint?response_type=$responseType&client_id=$clientId&redirect_uri=$redirectUri&scope=$scope';

    try {
      final result = await FlutterWebAuth2.authenticate(
        url: authUrl,
        callbackUrlScheme: 'jukebox',
      );

      // Le jeton d'accès est inclus dans l'URL de redirection
      final token = Uri.parse(result).fragment.split('&').first.split('=').last;

      // Utilisez le jeton d'accès pour accéder aux ressources protégées
      // ...
    } catch (e) {
      // Gérez les erreurs d'authentification ici
      print(e);
    }
  }
}

Can you help me ?

Thanks in advance

ThexXTURBOXx commented 1 year ago

You have not used the appropriate issue template. Please, use the "Bug report" template for issues like this. This issue template would have guided you towards the troubleshooting guide. Also, you did not follow the setup guide correctly: https://github.com/ThexXTURBOXx/flutter_web_auth_2#windows-and-linux