firebase_auth_dart_platform 0.2.0
firebase_auth_dart_platform: ^0.2.0 copied to clipboard
Unofficial pure-Dart implementation of the FlutterFire Firebase Auth platform interface: the official firebase_auth API on Linux, or on any platform you choose.
0.2.0 #
-
Breaking: the package re-exports
secure_flow, which is now 0.2.0 (new enum values). Needsfirebase_auth_providers_dart0.4.0 andfirebase_auth_secure_storage_flutter0.1.1. -
The id of a
MultiFactorResolver.sessionis opaque (sign-in-<n>) instead of the backend's pending credential, so printing or logging the session shows no secret.verifyPhoneNumber(multiFactorSession:)with it still sends the SMS of the sign-in through the client's resolver, whose newsessioncarries the credential. -
initializeRecaptchaConfigreads the project's reCAPTCHA Enterprise configuration through the client (it threwunimplemented); the requests the project protects then carry a token of the newrecaptchaEnterprisesource ofFirebaseAuthDart.use, by default reCAPTCHA Enterprise in the app's page on the web and none elsewhere. -
On the web the
RecaptchaVerifierrenders the reCAPTCHA v2 widget in the page (InPageRecaptchaPresenterofsecure_flow):container,size,theme,onSuccess,onErrorandonExpiredmap onto it,render,verifyandclearwork, andsignInWithPhoneNumberandUser.linkWithPhoneNumbertake its token unlessusegot anappVerification. Elsewhere it still renders nothing. -
Exports
RecaptchaEnterpriseVerification,RecaptchaEnterpriseRequest,RecaptchaClientType,RecaptchaFlowandInPageRecaptchaPresenter; depends onsecure_flowdirectly. -
On the web the tabs follow each other's sign-outs and sign-ins: the storage wrapper passes on the changes of a storage that reports them (
ObservableAuthStorageoffirebase_auth_providers_dart, which the default IndexedDB/localStoragestorage andsessionStorageare) to the client, and ignores them once a failed write moved the session to memory. In front of a storage that does not report changes (the secure store on the other platforms) the wrapper is a plain storage, so the client does not read it before storing an update. Needs the next release offirebase_auth_providers_dart. -
The OAuth credentials the shim hands out (
UserCredential.credential,FirebaseAuthException.credential) no longer print their access token: theirtoStringshows only the provider and the sign-in method. The platform interface'stoStringprinted the token.asMap()is unchanged.
0.1.1 #
User.refreshToken: the client's refresh token while that user is signed in, null for aUserkept after a sign-out or a switch of user. FlutterFire's ownUser.toString()prints it, as on the native platforms.- Phone sign-in through the client:
verifyPhoneNumber(codeSentwith the verification id,verificationFailed,codeAutoRetrievalTimeoutaftertimeout; neververificationCompleted, since there is no instant verification or SMS auto-retrieval outside Android),signInWithPhoneNumberandUser.linkWithPhoneNumber(aConfirmationResultwhoseconfirmtakes the code),User.updatePhoneNumber, and phone credentials insignInWithCredential,linkWithCredentialandreauthenticateWithCredential. Every error ofverifyPhoneNumberreachesverificationFailed(internal-errorfor one that is not aFirebaseAuthException).linkWithPhoneNumberthrowsprovider-already-linkedbefore any SMS when the user has a phone number. Thecredentialofcredential-already-in-usesigns in to the account that has the number. FirebaseAuthDart.use(appVerification:): the proof of the phone requests, by default the reCAPTCHA v2 page of the client, shown by thepresenterofuse(the system browser on a desktop without one). With the Auth emulator, or aftersetSettings(appVerificationDisabledForTesting: true)(no longer ignored), no proof is sent.usealso registers aRecaptchaVerifierfactory, so thatsignInWithPhoneNumberwithout a verifier works; it renders nothing, andRecaptchaVerifier.verifythrowsunimplemented.- SMS second factors:
verifyPhoneNumberwith the session ofUser.multiFactor.getSession()(enrolment) or of aMultiFactorResolver(sign-in),PhoneMultiFactorGenerator.getAssertion, andMultiFactor.enrollandMultiFactorResolver.resolveSignInwith the assertion. - The real-project harness has
phoneandsmssteps for a test phone number of the console (AUTH_HARNESS_PHONE_NUMBER,AUTH_HARNESS_PHONE_CODE; skipped without them). - Tested with unit tests against a fake backend; the emulator tests and the harness steps are written but were not run.
- On the web the default storage of the sessions is
BestWebAuthStorageoffirebase_auth_providers_dart(IndexedDB, elselocalStorage, else memory) instead of memory, so the user stays signed in after a reload. A session an app kept inlocalStorageunder the same key moves to IndexedDB at the first read. setPersistenceon the web:LOCALandINDEXED_DBkeep the session in the storage of the app (that default, orstorageFor).SESSIONkeeps it in the tab'ssessionStorage(WebAuthStorage.session) when the app passed nostorageFor, and a reloaded tab restores it from there (asetPersistence(SESSION)at start keeps it); withstorageFor,SESSIONis memory as before.NONEis memory. Elsewhere nothing changes (SESSIONis memory).FirebaseAuthDart.use(storageFor: ...)still replaces the default. The web wiring is unit-tested on the VM with fakes; the shim has not been run in a browser.
0.1.0 #
- First version: an implementation of
FirebaseAuthPlatform(the platform interface of the officialfirebase_authplugin) on top ofFirebaseUserAuthoffirebase_auth_providers_dart, so that an app keeps the official API. - Registers itself on Linux;
FirebaseAuthDart.use()selects it on any other platform. Underflutter testthe registration keeps the sessions in memory and leavesfirebase_corealone. - A small pure-Dart
firebase_coreimplementation, installed on Linux only whilefirebase_corehas no other one, so that it can be in one app withcloud_firestore_dart_platform. - Sign-in anonymously, with email and password, a custom token, an email link and the credentials of federated
providers; account management, action codes,
tenantId,languageCode, the three streams,useAuthEmulator, and the session kept by one storage object for all apps (setPersistencemoves it to memory and back; when the storage cannot be written, the session stays in memory for the run). FirebaseAuthDart.userAuthFor(app): the client behind an app, also a token provider forcloud_firestore_dart.- Not implemented (
FirebaseAuthExceptionwith the codeunimplemented): provider, popup and redirect flows, phone sign-in, multi-factor authentication, token revocation, Play Games and Game Center credentials. - Multi-factor with an authenticator app (TOTP):
User.multiFactor.getSession,enroll,unenrollandgetEnrolledFactors,TotpMultiFactorGenerator.generateSecret,getAssertionForEnrollmentandgetAssertionForSignIn, andTotpSecret.generateQrCodeUrl.MultiFactorResolver.resolveSignInfinishes a sign-in or a reauthentication with a TOTP assertion.enrollwith a TOTP assertion and nodisplayNamethrowsargument-error;TotpSecret.openInOtpAppandPhoneMultiFactorGenerator.getAssertionthrowunimplemented. signInWithProvider,User.linkWithProviderandUser.reauthenticateWithProviderrun the loopback OAuth flow with the providers passed toFirebaseAuthDart.use(oauthProviders:); the scopes and custom parameters of the FlutterFire provider are added to the request.presenteronuse()(aSecurePresenterofsecure_flow) runs the browser part; it is needed on Android and iOS (without it the calls throwoperation-not-supported-in-this-environment, where they threwunimplementedbefore), and defaults to the system browser elsewhere (the URL on stderr over SSH or without a display). A presenter the flow refuses (a web view) isargument-error. A provider id that was not passed, and the web, throwunimplemented. The library exportsOAuthLoopbackProvider,OAuthAuthorizationCode,OAuthCodeExchange,SecurePresenter,SystemBrowserPresenter,ConsolePresenterandCallbackPresenter.revokeAccessTokenandrevokeTokenWithAuthorizationCode.- An error from the backend is a
DartFirebaseAuthException, aFirebaseAuthExceptionthat also hasserverCodeandhttpStatus. Multi-factor errors do not keep them, becausefirebase_authbuilds its own class for those. FirebaseAuthDart.validatePassword(app, password)checks a password against the policy of the project or the tenant, also on the emulator.FirebaseAuth.validatePasswordoffirebase_authdoes not go through the platform interface: it asks the production backend itself.- An
UnsupportedErrorof the client is aFirebaseAuthExceptionwith the codeunimplemented, and a call after the instance was disposed one withapp-deleted. setPersistencemoves the session with the client'ssetStorage. The session is still kept in memory when the storage of the app cannot be written.FirebaseAuthDart.use(oauthProvidersFor:): the loopback providers of one app, added tooauthProviders; a provider with the same id replaces the shared one for that app. ExportsOAuthProvidersFactory.- The default storage of the sessions is the secure store of the platform,
SecureAuthStorageoffirebase_auth_secure_storage_flutter(new dependency), on every platform but the web, which keeps memory. Linux builds now needlibsecret-1-dev, Windows builds the ATL libraries, and the macOS keychain thekeychain-access-groupsentitlement. - A session in the session file (
defaultSessionFile()) moves to the secure store at its first read (read back and compared before the file loses it); when both hold one, the secure store's wins and the file is left alone. - Before the first operation of a run, a probe writes, reads back and deletes
<namespace>/.probein the secure store (concurrent callers wait for it). When a step fails withSecureAuthStorageException.isUnavailable(no plugin, no Secret Service, a locked keyring, a missing macOS entitlement, Windows without an interactive logon), or there is no services binding, the run keeps the sessions in the session file instead (memory on Android and iOS), and one line per process says so. Other probe errors are thrown and the next operation probes again; other errors of the store are thrown and never answered from the file; a failed write still ends in memory throughFallbackStorage. - The marker of the secure store,
<session file>.secure(session key tosecureorsign-out, never a token), records the apps whose session lives in the store. A marked session is never read from or written to the session file: in a run where the store cannot be used (any reason, a locked keyring and Windows DPAPI refusing access included) it is kept in memory only, and a sign-in or sign-out there, or a write the store refuses later in a run, marks itsign-out; the next run that can use the store deletes it there before anything reads it. A copy left in the file by a crash during the move is deleted, never restored. storageForreplaces the default entirely; returning aFileAuthStorage(defaultSessionFile()!)keeps the file.