Closed JPFrancoia closed 1 year ago
Please try to run the example which works properly on my machine. If that also does not work, there might be something wrong with your setup
Sorry, didn't mean to close this issue
Ok I got it to work, I was pretty much there, the only thing was to make the backend redirect to the auth.html
from the app, and not serve this page directly from the backend:
c.Redirect(http.StatusFound, "http://localhost:8081/auth.html")
Where 8081 is the port number where the flutter app is running.
One last thing, do you know if there is a way to tell the backend (so that would be while calling FlutterWebAuth2.authenticate
) if the flutter app is running on a web platform or on Android?
Very nice to hear! :)
About your question: I think there are multiple ways to do it. One of them would be to identify the current platform in your app and passing it to your backend using a query parameter or similar. Another possibility would be to analyse the browser that is currently used to get the web page, but that can be spoofed, so it might be a bit unreliable.
For the former suggestion, you might want to use e.g. Platform.isAndroid
and kIsWeb
as shown in the example
Describe the bug
I can't get the authentication to work for the web platform. The authentication works on Android
To Reproduce
I have my own authentication/backend service to authenticate my users. The service is written in Go. The authentication flow works like this:
http://localhost:8080/auth/facebook
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 when the client is a simple html page that I serve from the
/login.html
endpoint of the backend. This html pages just contains a link that points tohttp://localhost:8080/auth/facebook
.I'm now trying to build a proper UI with Flutter. So far I have something like this:
On the server side, there are just 2 simple functions that are called. The
Login
function (behing the/auth/facebook
endpoint), which creates a Oauth link that the client will need to follow to start the auth flow:And the
AuthCallback
function, behind the/auth/callback
endpoint. This endpoint serves theauth.html
page from your docThis setup works for Android when the backend redirects to
callback-scheme://
. However it doesn't work for the web platform: when I click the login button, another tab opens with Facebook, I can give permissions for my app, then I'm redirected to theauth.html
page. The page is closed almost immediately (makes sense, since we're doingwindow.close()
there). But this line in the flutter app is never executed:And obviously if it's not executed, I can't get the token back.
Expected behavior
The
auth.html
page should be able to send information back to the main app.Device (please complete the following information!)
flutter_web_auth_2
version: latest as of 21/04/2023 (DD/MM/YY)Additional context
Add any other context about the problem here.
Checklist