सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
simple_auth_generator एक Flutter/Dart कोड जनरेटर है जो स्रोत_gen का उपयोग करके अनोटेटेड इंटरफ़ेस से HTTP क्लाइंट बनाता है। Retrofit और Chopper से प्रेरित, यह टाइप-सुरक्षित एंडपॉइंट, रिक्वेस्ट हैंडलिंग और सीरियलाइज़ेशन के साथ क्लाइंट क्लासेस स्वचालित रूप से उत्पन्न करके API एकीकरण को सरल बनाता है। विकासकर्ता एनोटेशन का उपयोग करके API को परिभाषित करते हैं, और जनरेटर साफ और बनाए रखने योग्य कोड उत्पन्न करता है। यह JSON सीरियलाइज़ेशन का समर्थन करता है और macOS, Windows और Linux प्लेटफॉर्म पर काम करता है।
उपयोग
प्रकार सुरक्षित HTTP क्लाइंट उत्पन्न करना
API एंडपॉइंट बॉयलरप्लेट को स्वचालित करना
न्यूनतम कोड के साथ RESTful सेवाओं का एकीकरण
JSON अनुक्रमण को सरल बनाना
Flutter ऐप में पुनर्उपयोगी API क्लाइंट बनाना
मुख्य विशेषताएँ
एनोटेशन-आधारित API परिभाषा
संकलन समय कोड उत्पादन
प्रकार सुरक्षित HTTP अनुरोध
निर्मित JSON अनुक्रमण
क्रॉस-प्लेटफॉर्म समर्थन (macOS, Windows, Linux)
इनके लिए उपयुक्त
Flutter विकासकर्ता REST APIs बना रहे हैं
कम बॉयलरप्लेट कोड वाली टीमें
रखरखाव योग्य HTTP क्लाइंट की आवश्यकता वाले प्रोजेक्ट
Retrofit/Chopper पैटर्न के साथ विकासकर्ता
कुशल JSON संसाधन की आवश्यकता वाले ऐप्स
विचार योग्य बातें
source_gen और अनुलेखन के बारे में ज्ञान की आवश्यकता है
HTTP क्लाइंट उत्पादन तक सीमित
कोई रनटाइम कॉन्फ़िगरेशन विकल्प नहीं
कोड जनरेशन के लिए build_runner पर निर्भर है
कस्टमाइज़ेशन के बिना अन्य REST API के लिए उपयुक्त नहीं है
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
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.