Posts

Showing posts from 2022

Flutter Web, a Dart gRPC server and Firebase Authentication

Image
OK, not the sexiest title, but here is a quick overview of how you can create a flutter web application (or mobile for that matter, but more on that later), using Firebase authentication , talking to a pure Dart server using gRPC.   The goal here is to: Create a SPA Flutter web application. Leverage Firebase authentication. It's inexpensive (essentially free for most users), and supports a wide variety of social login providers. Support a native Dart Server, using gRPC and protobufs. Proxy from gRPC web to gRPC "native" using envoy. Putting it together, it looks something like this: Why the choice of gRPC here, instead of json/REST?  This comes down to personal preference, but I have always liked the contract first approach of gRPC of defining interfaces using protobufs. In theory, you can do this with OpenAPI - but I've yet to see a moderately complex interface where the generated API stubs look even remotely usable. gRPC does a good job of generating usable client a

Firebase Authentication with a custom Dart Server

Image
  This post describes my experiments using  Firebase Authentication  with a  Dart  Server application (for example, a  shelf  based web app). The scenario is that you have a client application (a Flutter Web app, for example) that you want to authenticate using Firebase, but the backend is your own custom web application instead of hosted Firebase services. Firebase Authentication is essentially free, and offers social login with all the usual suspects  in addition to username/password and phone number authentication. Why roll your own IAM when you can get it for free? There are examples of this hybrid scenario for other languages where there is a Firebase admin SDK, but I couldn't find detailed notes on how to do this using Dart on the backend. Before we get to the solution (which turns out to be fairly simple), a quick detour into some of the workings of Firebase AuthN. Once Firebase successfully authenticates your client, it issues it an JWT Identity Token (idtoken). To play aro

Notes on Firebase auth for Flutter Web

Flutter Web and Firebase Authentication with Google. Issue "not a valid origin" Notes to self... Despite registering the IntelliJ web server origin in the client OAuth2 settings in the  Cloud Console ,  (for example http://localhost:53006),  sign in with Google produces the error: Error: PlatformException(idpiframe_initialization_failed, Not a valid origin Not sure why the origin did not take in the console,  possibly because of firebase integration with google cloud?  Stackoverflow to the rescue:  https://stackoverflow.com/questions/65132622/firebase-google-signin-localhost-not-whitelisted   This configures Intellij to run the web server on port localhost:5000, which *is* auotmatically registered by firebase as a valid origin for local development.