Open Nealsoni00 opened 3 years ago
Just figured this out. Its actually ridiculously simple. You just spin up an http server on localhost
and listen for the redirect. This technique should probably work for everything but web.
Technique described here: https://stackoverflow.com/questions/68716993/google-microsoft-oauth2-login-flow-flutter-desktop-macos-windows-linux
TLDR: Implement a listen function like this:
static Future<Uri> listenForAuth() async {
HttpServer server = await HttpServer.bind("localhost", 80);
final req = await server.first;
final result = req.uri;
req.response.statusCode = 200;
req.response.headers.set("content-type", "text/plain");
req.response.writeln("Authentication successful! You can close this tab.");
await req.response.close();
await server.close();
return result;
}
Here is my working solution for now: oauth2.txt
Replace these
final file = File("...\\client_credentials.json");
late DesktopOath2 auth;
if (file.existsSync()) {
auth = DesktopOath2.fromCredentials(file.readAsStringSync(), GoogleAppSecret(),
GoogleOath2Endpoint(), GDrive.getScopes());
} else {
auth = DesktopOath2(GoogleAppSecret(), GoogleOath2Endpoint(), GDrive.getScopes());
}
await auth.login();
file.writeAsString(auth.toJsonCredentials());
final drive = DriveApi(auth.authClient);
final files = await drive.files.list(...)
I used this approach as _google_signin does not yet support windows desktop. I might write a ticket to them.
Just figured this out. Its actually ridiculously simple. You just spin up an http server on
localhost
and listen for the redirect. This technique should probably work for everything but web.Technique described here: https://stackoverflow.com/questions/68716993/google-microsoft-oauth2-login-flow-flutter-desktop-macos-windows-linux
TLDR: Implement a listen function like this:
static Future<Uri> listenForAuth() async { HttpServer server = await HttpServer.bind("localhost", 80); final req = await server.first; final result = req.uri; req.response.statusCode = 200; req.response.headers.set("content-type", "text/plain"); req.response.writeln("Authentication successful! You can close this tab."); await req.response.close(); await server.close(); return result; }
This answer helped me, but I think it's worth to point out that you need to add your localhost url to Azure in order for it to work:
Hey all! I'm trying to implement OAuth2 ID Token Grant Flow on a Windows desktop app. I noticed the OAuth2 plugin supports Windows and MacOS but in the documentation on listening for the redirect using
uni_links
. Howeveruni_links
only supports iOS/Android/Web.Does anyone have examples of how they can register a windows app to receive the OAuth redirect?