How can I build a Go Library and use it in Flutter?

Viewed 322

I'm currently trying to use Azure Authentication within my Flutter app. I've searched and have not found an existing library that supports MSAL/AAD for Flutter on Windows.

If I use the MSAL package within Visual Studio for a WPF app, the authentication works fine, so the app within Azure is set up correctly. I think I need to use the legitimate client tooling that Microsoft provides in order to get my tokens and such.

Unfortunately, Flutter doesn't provide any integration with .NET, so I can't write a platform-specific integration in .NET and then the rest of my app in Flutter, so that's a shame. But it seems like Flutter can reference a standard C library.

It also seems like Microsoft makes a client for Go, and Go can compile to a C Shared library. So, in my mind, I should be able to compile this library to a C Shared library, and then write up my platform specific implementation in Flutter. In my attempts to build the MSAL GO library so far, it seems like because the MSAL GO library (https://github.com/AzureAD/microsoft-authentication-library-for-go) lacks a main method, and is more to be used as a plugin, so it can't be built directly into a c-shared library by Go.

How can I build the Microsoft MSAL library as a c-shared library? Please note, I am hilariously new to Go.

1 Answers

This does not answer your question directly, but it has been done without any plugin or native development, as far as I understand:

https://blog.objektkultur.de/azure-ad-authentication-flutter-apps/

I also looked up available libraries for AzureAD, and besides the Go library there seem to be versions for Java and ObjectiveC, which you could use to develop your own integration using Flutter platform channels for example.

If you really want to use Go from within Dart / Flutter, I would try to compile the Go code to web assembly and use something like:

https://pub.dev/packages/wasm

No guarantee, this leads in the right direction, though.

Related