Package selection guidance compiled from public package information, community data, and project usage.
simple_auth_generator is a Flutter/Dart code generator that creates HTTP clients from annotated interfaces, leveraging source_gen for compile-time code generation. Inspired by Retrofit and Chopper, it simplifies API integration by automatically generating client classes with type-safe endpoints, request handling, and serialization. Developers define APIs using annotations, and the generator produces clean, maintainable code. It supports JSON serialization and works across macOS, Windows, and Linux platforms.
Use cases
Generating type-safe HTTP clients
Automating API endpoint boilerplate
Integrating RESTful services with minimal code
Streamlining JSON serialization
Creating reusable API clients in Flutter apps
Key features
Annotation-based API definition
Compile-time code generation
Type-safe HTTP requests
Built-in JSON serialization
Cross-platform support (macOS, Windows, Linux)
Suitable for
Flutter developers building REST APIs
Teams seeking reduced boilerplate
Projects requiring maintainable HTTP clients
Developers familiar with Retrofit/Chopper patterns
Apps needing efficient JSON handling
Considerations
Requires knowledge of source_gen and annotations
Limited to HTTP client generation
No runtime configuration options
Depends on build_runner for code generation
Not suitable for non-REST APIs without customization
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
Most apps need to make API calls. Every API needs authentication, yet no developer wants to deal with authentication. Simple Auth embeds authentication into the API so you dont need to deal with it.
And of course any standard OAuth2/Basic Auth server.
Usage
var api = new simpleAuth.GoogleApi(
"google", "client_id",clientSecret: "clientSecret",
scopes: [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile"
]);
var request = newRequest(HttpMethod.Get, "https://www.googleapis.com/oauth2/v1/userinfo?alt=json");
var userInfo = await api.send<UserInfo, UserInfo>(request);
That's it! If the user is not logged in, they will automatically be prompted. If their credentials are cached from a previous session, the api call proceeds! Expired tokens even automatically refresh.
Flutter Setup
Call SimpleAuthFlutter.init(); in your Main.Dart. Now Simple Auth can automatically present your login UI
Redirect
Google requires the following redirect: com.googleusercontent.apps.YOUR_CLIENT_ID
Simple Auth by default uses SFSafari on iOS and Chrome Tabs on Android.
This means normal http redirects cannot work. You will need to register a custom scheme for your app as a redirect. For most providers, you can create whatever you want. i.e. com.myapp.foo:/redirct
Android Manifest
you would then add the following to your Android manifest
Note, if you want to avoid Apples mandatory user consent dialog
"foo" Wants to use "bar.com" to Sign In
This allows the app and website to share information about you.
add the lines above and set FooAuthenticator.useSSO = false; which will not use SFAuthenticationSession on iOS, and ASWebAuthenticationSession on macOS. This is the default behavior for the Keycloak provider.
Serialization
Json objects will automatically serialize if you conform to JsonSerializable
If you use the generator and you objects have the factory factory JsonSerializable.fromJson(Map<String, dynamic> json) your api calls will automatically Serialize/Deserialize
Or you can pass your own Converter to the api and handle conversion yourself.