authpass / autofill_service

Implements a very simple version for android autofill service as a plugin for flutter. https://authpass.app/
GNU General Public License v3.0
23 stars 10 forks source link

How does the autofill service connect to your credential database? #2

Closed OGmetamonkey closed 3 years ago

OGmetamonkey commented 4 years ago

Thank you for sharing this implementation. I'm playing around with it. I was able to implement the autofill service for a sample application with an encrypted database that holds credentials, however the autofill service isn't connected to the credential database. I'm having trouble following the logic on the autofill service connection. So, when I select "autofill with sample application", nothing happens.

Is there any way you could provide any guidance on how to connect the autofill service to the application database so that the autofill service will function with my database?

hpoul commented 4 years ago

The library pretty much just solved my problem with implementing a password manager so ymmv. The way it works is, it simply displays the 'autofill with xxx' dialog for username/password fields, and on click will launch the activity with flutter with an initial route of /autofill - the flutter part in the activity would then have to find the correct credentials and call back to the plugin.. the plugin would then finish the plugin with the appropriate activity result.

Feel free to check out how AuthPass uses it:

https://github.com/authpass/authpass/blob/8f7a9528539d277ae469da7eb496d6856c168cf2/authpass/lib/ui/screens/password_list.dart#L189-L190

OGmetamonkey commented 4 years ago

Thanks for the tips! Very appreciative. Still struggling with trying to find where that "/autofill" route is declared and the actual activity it calls. I tracked "autofill with xxx" down to FlutterMyAutofillService.kt and changed that label with success, however I'm having trouble finding the connection from that popup button to the route and link to the activity you gave of passwordlist.dart with: AutofillService().resultWithDataset( label: entry.label, username: username, password: password);

Will keep trying. Any additional tips are very appreciated!

hpoul commented 4 years ago

you can basically just search for /autofill: https://github.com/authpass/autofill_service/blob/6dd832d88543e289e422fb50286885bbc3049576/android/src/main/kotlin/design/codeux/autofill_service/FlutterMyAutofillService.kt#L77

this starts the MainActivity which contains the flutter app. Unfortunately it looks like i've just hardcoded that:

https://github.com/authpass/autofill_service/blob/6dd832d88543e289e422fb50286885bbc3049576/android/src/main/kotlin/design/codeux/autofill_service/FlutterMyAutofillService.kt#L68-L69

To make it more generic this should probably get configurable.. like through a <meta-data> in the AndroidManifest.xml or something like that.

OGmetamonkey commented 4 years ago

How did you set that to launch main activity? AKA, how did you get the service to link "design.codeux.authpass.MainActivity" to the authpass main activity? When I used my app name for that ("design.codeux.myappname.MainActivity"), nothing happens.

hpoul commented 4 years ago

huh? you need to set it to the fully qualified classname of your main activity..

OGmetamonkey commented 4 years ago

Ok. Apologies. I’m not familiar with kotlin or accessing activities from outside of flutter. I’ll have to figure out how to find the fully qualified class name.

On Thu, Aug 20, 2020 at 5:17 PM Herbert Poul notifications@github.com wrote:

huh? you need to set it to the fully qualified classname of your main activity..

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/authpass/autofill_service/issues/2#issuecomment-677909993, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD5IQJEFBAXKZKY4YCFPFJLSBWHGNANCNFSM4QEDZBBA .

-- Jake Brantley CEO 865-964-8783

OGmetamonkey commented 4 years ago

Ok, so the fully qualified class name for the activity is the package name and the desired activity. I didn't realize we would be deep linking into the app for this. Got the deep link working.

Are you launching an isolate when you deeplink from the form field or launching the whole app?

hpoul commented 4 years ago

in AuthPass I simply launch the whole app. And even create a new instance of the Activity altogether.. ie. a whole new FlutterEngine. I looked into reusing the same FlutterEngine instance as the main "task" of the app, but the add2app documentation was a big vague about if I attach the FlutterEngine to a second surface and keep the whole app state alive.. but it worked for me just launching a whole new activity

OGmetamonkey commented 3 years ago

I went ahead and closed this issue as you have clarified it for me. Will contact you with progress on another implementation in the case it is useful to your project.