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

doesn't capture my callback #16

Closed oshju closed 1 year ago

oshju commented 1 year ago

same as title doesn't capture my callback.don't why

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

import 'dart:convert' show jsonDecode; import 'package:http/http.dart' as http;

// App specific variables final googleClientId = 'client'; final callbackUrlScheme = 'com.example.ui://callback';

// Construct the url final url = Uri.https('bungie.com', '/en/oauth/authorize', { 'client_id': googleClientId, 'response_type': 'code', });

// Present the dialog to the user Future<String?> getGoogleAuthCode() async { final result = await FlutterWebAuth2.authenticate( url: url.toString(), callbackUrlScheme: callbackUrlScheme, );

// Extract the code from the response URL

//String casteo = getGoogleAuthCode().toString(); //final result = await FlutterWebAuth2.authenticate(url: url.toString(), callbackUrlScheme: callbackUrlScheme);

// Extract code from resulting url final result1 = Uri.parse(result).queryParameters['code']; print(result) { // TODO: implement print throw UnimplementedError(); }

var headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'code': '$result1', }; var request = http.Request( 'POST', Uri.parse('https://www.bungie.net/platform/app/oauth/token'));

request.headers.addAll(headers);

http.StreamedResponse response = await request.send();

if (response.statusCode == 200) { print(await response.stream.bytesToString()); } else { print(response.reasonPhrase); }

// Extract the access token from the response //final data = jsonDecode(response.body);

// Use the access token to access the Google API

// Do something with the data }

void main() { runApp(miercoles()); }

class miercoles extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: Text('Google Sign In'), ), body: Center( child: ElevatedButton( child: Text('Sign in with Google'), onPressed: () async { // Get the auth code

          getGoogleAuthCode();
        },
      ),
    ),
  ),
);

} } my android manifest `<activity android:name="com.linusu.flutter_web_auth.CallbackActivity" android:exported="true" tools:ignore="MissingClass">

     </activity>`
ThexXTURBOXx commented 1 year ago
import 'package:flutter_web_auth/flutter_web_auth.dart';

It seems like you have flutter_web_auth and flutter_web_auth_2 installed simultaneously. Could you please try removing flutter_web_auth?

oshju commented 1 year ago

ok

oshju commented 1 year ago

still happen image

ThexXTURBOXx commented 1 year ago

The webpage is showing the URL as com.example.ui:/?code=... However, the callback scheme you provided is com.example.ui://callback. Please change this in your Android Manifest to com.example.ui and in your dart file to final callbackUrlScheme = 'com.example.ui';

ThexXTURBOXx commented 1 year ago

Also, the backend on web should redirect to com.example.ui://?code=... instead. Please note the DOUBLE-slash (not one as seen in your screenshot above)

oshju commented 1 year ago

i added like you say https://github.com/oshju/webauthmiercoles.git no works

ThexXTURBOXx commented 1 year ago

You have not applied the changes I suggested. Your Android Manifest is still faulty and the dart code has also not been modified. Also, your web application does need the suggested change as well.

oshju commented 1 year ago

i tried with one slash and 2 slash

ThexXTURBOXx commented 1 year ago

As already said, this line should say <data android:scheme='com.example.ui' /> and this line should say final callbackUrlScheme = 'com.example.ui';. Google OAuth should redirect to com.example.ui://?code=... instead. After these changes, everything will work fine, as already stated. Please take a look at the example for each package for the future before creating issues.