Simple Auth ist der einfachste Weg, Ihre Benutzer/APIs zu authentifizieren. Dieses Plugin speichert Token/Berechtigungen sicher und zeigt bei Bedarf automatisch die Anmelnoberfläche an.
Aus öffentlichen Paketdaten erstellte Orientierung.
Simple Auth Flutter ist ein leichtgewichtiges Authentifizierungspaket, das die Benutzerauthentifizierung in Flutter-Apps vereinfacht. Es speichert Tokens und Anmeldeinformationen sicher, zeigt die Login-Oberfläche automatisch an, wenn erforderlich, und integriert sich nahtlos mit verschiedenen Identitätsanbietern. Entwickelt für einfache Bedienung verringert es Boilerplate-Code, während Sicherheitsbest Practices eingehalten werden. Das Plugin unterstützt Android, iOS und macOS und ist daher ideal für plattformübergreifende Anwendungen mit einfachen Authentifizierungsabläufen.
Anwendungsfälle
Benutzeranmeldung und Sitzungsverwaltung
Automatische Neuanmeldung
Sichere Token-Speicherung
Integration mit OAuth-Anbietern
Plattformübergreifende Authentifizierung
Hauptmerkmale
Sichere Anmeldeinformationen-Speicherung
Auto-Login-UI-Eingabeaufforderung
Minimale Einrichtung
Unterstützt mehrere Plattformen
Eingebaute Token-Persistenz
Geeignet für
Anfänger-Flutter-Entwickler
Apps, die grundlegende Authentifizierung erfordern
Projekte mit engen Fristen
Plattformübergreifende Mobile Apps
Einfache Anmeldevorgänge
Hinweise
Eingeschränkte Anpassungsmöglichkeiten für Anmeldebildschirme
Nicht geeignet für komplexe Authentifizierungsabläufe
Abhängig von externen Anbieterimplementierungen
Keine integrierte Benutzerregistrierung
Erfordert sorgfältige Handhabung der Token-Aktualisierungslogik
Original-README
Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.
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.