Skip to content

Can't get web auth to work with my own authentication server #154

@JPFrancoia

Description

@JPFrancoia

Hello,

I have my own authentication service to authenticate my users. The service is written in Go. The authentication flow works like this:

  • the client queries http://localhost:8080/auth/facebook
  • the client is redirected to a facebook page where the user will authorize my app
  • facebook then redirects to http://localhost:8080/auth/callback with the user info (I do stuff with this data, like adding the user to a database)

The above works. I'm now trying to build the UI. So far I have something like this:

import 'package:flutter/material.dart';
import 'package:social_login_buttons/social_login_buttons.dart';
import 'package:flutter_web_auth/flutter_web_auth.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Sample',
      home: LoginPage(),
    );
  }
}

class LoginPage extends StatelessWidget {
  LoginPage({super.key});

  @override
  Widget build(BuildContext context) {

    return LayoutBuilder(builder: (context, constraints) {
      return Scaffold(
        body: SocialLoginButton(
          buttonType: SocialLoginButtonType.facebook,
          onPressed: () async {
            final result = await FlutterWebAuth.authenticate(
                url: "http://localhost:8080/auth/facebook", callbackUrlScheme: "callback-scheme");

            print("result: $result");

            final token = await Uri.parse(result).queryParameters['token'];
            print(token);
          },
        ),
      );
    });
  }
}

On the server side, this is the implementation of the /auth/callback endpoint:

func AuthCallback(c *gin.Context) {
	user, err := gothic.CompleteUserAuth(c.Writer, c.Request)

        ...

	c.HTML(http.StatusOK, "auth.html", gin.H{})
	// c.Redirect(http.StatusFound, "callback-scheme://")
}

I tried serving the auth.html page mentioned here from the server. With this setup, I can click the Facebook button, the web page opens, I can login on Facebook, and I can give permissions to the app. I'm then redirected to the auth.html page, and then...nada. I never get back anything for final result =... (on the client side). There is no error in the flutter console.

I tried other stuff on the server side:

	c.JSON(http.StatusOK, gin.H{"token": "hello"})

With this, I ultimately a json blob with the hello token in the web page that opens, but I'm not getting anything back on the client side.

I'm missing something, but I don't know what. Would you be able to help please?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions