aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.

Home Page:https://docs.amplify.aws

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[RFC]: Amplify Flutter

Amplifiyer opened this issue · comments

This issue is a Request For Comments (RFC). It is intended to elicit community feedback regarding support for Amplify library in Flutter platform. Please feel free to post comments or questions here.

Purpose

Currently there is no official support for integrating with Amplify libraries in Flutter apps. This RFC goes over a proposal to build and release Amplify libraries in pub.dev that can be used in cross platform flutter apps.

Goals

  • Amplify iOS and Amplify Android parity: We would like to support all the use cases supported by these platforms in Amplify Flutter, including the following categories
    • Analytics
    • API (Rest/GraphQL)
    • Authentication (including Hosted UI)
    • DataStore
    • Predictions
    • Storage
    • Hub Events (Listening to the Amplify events)
  • Consistency with other platforms: Keep the public interface and API behavior consistent with Amplify iOS and Android libraries.
  • Pluggability: Customers should be able to implement/add their own cloud provider plugins for a given category.
  • UI Components: Provide a set of UI components intended to help developers leverage Amplify categories such as API, Auth, Storage etc.

Definitions

Categories: Use case driven abstractions such as Auth, Analytics, Storage that provide easy to use interfaces.
Providers: A cloud provider or a service provider such as Cognito, Auth0 in Auth category; Kinesis, Pinpoint and Firehose in Analytics Category; Rekognition, Textract in Predictions Category.
Plugins: Also called Amplify Plugins, bind providers to categories. They implement provider functionalities adhering to categories easy-to-use interfaces. Amplify Plugins already exist in native platforms (iOS/Android), this RFC explores creation of similar plugins in Flutter.
Flutter Plugins/Platform Plugins/Federated Plugins: These are native platform code and modules that is called from flutter apps or libraries over a method channel.

Proposed Solution

High Level Overview

Amplify flutter will be architected as a pluggable interface across all the categories listed in the Goals. The pluggable interface will allow plugging in different cloud providers (e.g. Auth0 or Cognito for Auth category) which can be written either entirely in Dart or using Flutter's Platform Plugins to reuse native (iOS and/or android) modules.

The core of Amplify Flutter will be written in Dart which provides the pluggable interface and out of the box AWS cloud provider plugins will utilize existing Amplify Android and Amplify iOS libraries as Flutter's federated plugins. This means that we will not be implementing a Dart aws-sdk right away as AWS service calls will be made by Amplify Android/iOS libraries.

The Amplify flutter library will be compatible with Amplify CLI to create and provision your cloud providers' resources. Amplify CLI will generate a configuration file to easily configure your Flutter app to use these resources.

Pros

  1. We can reuse most of the existing Amplify native libraries' AWS providers and ship to customers faster.
  2. Some initial bench-marking proves that executing native platform code is generally faster than dart code.
  3. New features introduced in native libraries can be made available in Flutter with very minimal to no change.
  4. Provides flexibility to write providers' (AWS or others) implementation entirely in Dart if needed in the future.

Amplify Flutter(2)

Developer Experience

  • Creating and provisioning resources will remain the same with amplify CLI https://docs.amplify.aws/cli/start/workflows
  • Integrating with Amplify Flutter
    • Flutter Apps will import AmplifyCore and the plugins they want to use in the app.
    • In the app, developers will be required to call Amplify.addPlugin() for each plugin they import e.g. Amplify.addPlugin(CognitoAuthPlugin())
    • Developers will call Amplify.Category.<API> to use installed plugins, e.g. Amplify.Auth.signIn()
  • Developing and debugging Amplify Flutter
    • Refer official flutter guide to learn how to debug provider plugins that are written entirely in Dart and the ones that use platform federated plugins.
  • Using Amplify UI components for Flutter - Coming Soon

FAQs

Q. Which versions of Android and iOS are supported?
Same versions as supported by Amplify Android and Amplify iOS libraries.

Q. How will escape hatches work with Amplify plugins that use native libraries?
Coming Soon.

Q. How will events that are emitted in native libraries reach Flutter apps.
We will use Flutter's event channels to subscribe events on the native platform and transmit them over to Dart end.

Q. Will web and Desktop platform be supported?
Not right away, our goal with this design is to keep the architecture flexible such that more platforms can be supported in the future.

Q. Can I migrate my Amplify CLI generated config from Android, iOS or JS platform to flutter?
Not right now. We will look into the feasibility of supporting this in the future.

Glad to hear that Amplify support is coming.

Can I please request that this supports custom authentication flows?

The current Amplify documentation pages for Android and iOS suggest initiating auth with username and dummy password and then changing the Cognito Define Auth Challenge to override the SRP_A challenge with a custom challenge. This effectively means you can't have both flows for a single Cognito user pool.

We have two applications which use the same user pool but have different sign in methods - one is custom and one is SRP_A. I am unable to use Amplify because I'm forced to do this hacky override in the Cognito trigger so we've resorted to using the Cognito SDK (non-amplify) directly.

I believe custom flow may already be implemented in the JavaScript library because the password parameter is optional on the signIn function: https://aws-amplify.github.io/amplify-js/api/classes/authclass.html#signin but this is not the case for Android or iOS so I'm not sure if this is in scope for this project or not. I can raise this as an issue in the Android and iOS repos too if necessary.

Can I please request that this supports custom authentication flows?

@andyfurniss4 Thanks for your feedback - we will definetely investigate this feature request!

Are there any plans to actually implement the client libraries in native dart code? Would be nice not to rely on platform messages to just bridge everything to the android/iOS libraries, this would make it work on all platforms (ie. also on desktop platforms macos, windows, linux). It gets really great when you can use the same code for mobile and desktop ;-)

In future can we expect Amazon SNS wrapper as part this package ? This will give us the ecosystem of various AWS features in single package.

At the moment there is no federate sign in methods. Did I missed something or is actually still to be implemented?

Honestly, we are not that bothered with auth as it is something easy to do without AWS. What we want to have is DataStore sync like Google Firestore.

I'm looking forward to the feature Datastore..

@dedecube OAuth authentication is definitely on the roadmap!

DataStore and API would be great to have

commented

DataStore and API (Rest and GraphQL) asap please. I am in love with flutter and want to use AWS as my backend for the project I am designing. I don't want to give in and use firebase. Any idea what the timeline will look like. Even preview will work!

Agree. Can't wait to switch from firebase to amplify.

DataStore and API (Rest and GraphQL) are definitely a big need. Is there a time table for when we can see these added?

We need AppSync!

As you can see, we're all pretty desperate for DataStore. If we could do anything to help I would gladly open pull requests but is there a list of things TODO ? 🥴

Hi all, we are currently working on the design for the datastore and will put it here or in another RFC to gather feedback. Please stay tuned.

Hi all, we are currently working on the design for the datastore and will put it here or in another RFC to gather feedback. Please stay tuned.

Edit (2021-02-16): Flutter SDK now supports DataStore so no need for the following hack.

If you are impatient like I am 😏, or your product release schedule can't be adapted to wait for DataStore support in this library, then you can write your own Flutter DataStore platform plugin that lives alongside this library.

I've created an example Flutter plugin and app to demonstrate a way to do this. That code can be found here: https://github.com/kjones/flutter-datastore-example

This is not a generic solution that will work with any GraphQL schema. It has to be targeted specifically to match your schema. Dart model classes have to be hand rolled since the Amplify codgen tools don't yet support Dart.

While this solution is far from perfect, it should give you a head start on using DataStore in your Flutter app while we wait for official support.

Is there a timeline for supporting Flutter Web with AWS? I can get it working great on the iOS simulator but it can't configure amplify when running on web. Would be great to have the web app running too!

commented

hate to ask a question like this, but I am wondering about the timeline for "production-grade" authentication. Currently, I am working on a big project with about a year-long timeline. Our stack is built primarily with flutter and aws services and we have tested "hello world" auth via amplify and it works great. However, because these features are labeled as "previews" and explicitly recommended not to be used in production, I was wondering when there would be reasonable certainty in the viability of flutter auth with amplify. Thank you!

@simonmahns I hear if you email your concerns to jeff@amazon.com enough times he forwards it to the right person to resolve 😅

Is there a weekly or bi-weekly progress report so we can know what to expect?

@Amplifiyer thanks for the update on DataStore. If there's any update, would love to hear it. Also, more than happy to help alpha test anything :)

@jamesdixon, we had been designing the datastore category for flutter and starting the implementation now. Stay Tuned!. I'll be putting up an RFC soon on this repo for visibility.

+1 desperate for DataStore.

Hi all,

We just posted an RFC for DataStore. Please take a look and give us your feedback: #160

Hello

I would like to know when amplify will be ready for use in production in the authentication package and if it is working in the rememberDevice function as it is in android

Any new updates?

@rlee1990

The team has been working hard on building DataStore, and we will share some bigger updates related to that pretty soon.

Amplify DataStore for flutter is now available as a developer preview. Get started here

What is the backend database for the datastore?

Amplify DataStore for flutter is now available as a developer preview. Get started here

What is the backend database for the datastore?

DynamoDB, via AppSync.

What's the local database implementation?

What's the local database implementation?

Amplify DataStore for flutter uses amplify-android and amplify-ios as platform plugin providers and both of them use SQLite for their local database implementation.

Hi folks! Any idea of the timeline on oAuth / Federated login support for the social providers supported by Cognito? Thanks.

I noticed functions was not listed in the categories expected to be supported. Obviously it has dependent on API, but is this also being considered?

@Amplifiyer @haverchuck
When do you expect Third-Party Sign-Ups (Google, Apple, Facebook) to be implemented?

Things described here: https://docs.amplify.aws/lib/auth/social_signin_web_ui/q/platform/android#add-response-handler

Hi all, we just posted this RFC regarding a refactor that could impact the way you use the library. Please take a look and let us know your feedback and opinions: #263

this is not the path I would have expected
we will not be implementing a Dart aws-sdk right away as AWS service calls will be made by Amplify Android/iOS libraries

I think the other way around would make more sense since with flutter you get Android, iOS, Web, Desktop support with a single codebase.
No way to beat Firebase and GCP without full dart-sdk, IMHO.

What is Datastore's current support for synchronization? Is sync control in the pipeline for flutter?

It currently syncs from client to DynamoDB table almost instantly, but the other way around (DynamoDB to Client) doesn't happen unless I clear local storage, run the query again, which pulls all data back from the cloud. Since my app users only periodically need their data from the DynamoDB table, a selective sync function (like what's available in Amplify for Android) would be much appreciated!

@nithin-seenivasan sync from (DynamoDB to Client) should work without issues, can you create a new issue with reproduction steps? Selective sync though is slightly different and is currently not implemented in amplify-flutter. Please create a feature request issue for that as well.

Any plan on adding push notification support like the firebase does with firebase_messaging that would integrate with SNS?

Any plan on adding push notification support like the firebase does with firebase_messaging that would integrate with SNS?

@jobypthomas This is definitely something we are planning to add to our roadmap for this year. Please go ahead and open up a feature request with what you would like to see supported for notifications. This would help other customers upvote/contribute as well.

Is phone authentication using otp supported in amplify flutter as of now?

@SatyamKr07 By 'otp support', do you mean two-factor authentication, or do you mean passwordless login? If the latter, are you assuming that you'd use a custom auth flow with lambda triggers?

@SatyamKr07 By 'otp support', do you mean two-factor authentication, or do you mean passwordless login? If the latter, are you assuming that you'd use a custom auth flow with lambda triggers?

Passwordless login where user inputs phone(mobile) number, receives otp via SMS, click on verify otp, and if otp entered is correct, user is logged in. So is this possible amplify flutter plugin as I could not find any resource?

I tried to follow "https://github.com/aws-amplify/amplify-flutter" and use local clone of "amplify-flutter" instead of the pub.dev amplify_core library, but "Amplify()" class is not recognized. Am I missing anything?

I tried to follow "https://github.com/aws-amplify/amplify-flutter" and use local clone of "amplify-flutter" instead of the pub.dev amplify_core library, but "Amplify()" class is not recognized. Am I missing anything?

Some breaking changes went into mainline, recently. Please see #263 and #273.

TLDR: Amplify() doesn't get instantiated, anymore. Now, you do Amplify.configure(...), etc.

@jobypthomas please see this new docs if you are running the repo's main branch to access Amplify object.

Any plan on adding push notification support like the firebase does with firebase_messaging that would integrate with SNS?

@jobypthomas This is definitely something we are planning to add to our roadmap for this year. Please go ahead and open up a feature request with what you would like to see supported for notifications. This would help other customers upvote/contribute as well.

Hi if nobody created this feature request, I will create a feature request on the push notification support describe according to @jobypthomas. I am working on a project using amplify and required push notification. Looking forward to see how amplify can enable this feature.

@Amplifiyer any timeline on support for GraphQL APIs?

any timeline on support for GraphQL APIs?

It has been there since 0.0.1-dev.6 I think?
https://docs.amplify.aws/lib/graphqlapi/getting-started/q/platform/flutter

Did not see that thanks

@rlee1990 Graphql query and mutations are currently supported in the latest versions. Subscribe API will be available in our next versions.

@Amplifiyer thanks for updating us on the subscriptions API, will this be a Dart implementation or calling the iOS and Android libraries? If so then I think we can use this for Desktop I would think.

@joekendal, this will be a wrapper over iOS and Android libraries.

@Amplifiyer
Can you give us update about when Third-Party Sign-Ups (Google, Apple, Facebook) are gonna be implemented?
At least more or less estimation :)

@BaranMichal25, we recently released 0.0.2-dev.1 version which has this feature (Hosted UI or Social SignIn). More details here https://docs.amplify.aws/lib/auth/signin_web_ui/q/platform/flutter

@Amplifiyer
woah, that's great news, thanks! :)

Can you give me an estimate when Apple Sign In will be supported as well?

@BaranMichal25, we haven't tested Apple SignIn yet, it should work though when you follow the steps here. Couple of points to note are

  1. Apple SignIn is currently not supported to be provisioned (or setup) through amplify cli as mentioned in the above link.
  2. You won't be able to launch the Apple Sign In page directly using the provider input. When you call Amplify.Auth.signInWithWebUI();, all the third party providers configured with Cognito will be available for sign in (including Apple). Once we complete the testing, we will add this provider so you can launch Apple sign in directly (bypassing the Cognito's hosted UI)

@Amplifiyer
Thanks, I followed the steps you mentioned and it mostly worked, which is great.

I just have one issue currently:

  1. I call the Amplify.Auth.signInWithWebUI();
  2. A general sign up page is displayed with all 3 party providers I'm using
  3. I choose Apple, authorise, looks like everything is successful, but:
    I end up on a blank page and nothing happens.
  4. If I click cancel on the browser and then call Amplify.Auth.signInWithWebUI(); again, then I'm automatically correctly authorised and navigated back.

So it looks like authentication worked, but just something is wrong with redirects or some callbacks?
Do you have any ideas or suggestions about what might be going wrong?

Thanks @BaranMichal25 for trying this out and letting us know the issue and reproduction steps. We will try to reproduce this on our end. It will help if you can open a new issue with the same details to help us track better.

Hi @Amplifiyer. Is custom auth supported by this library yet? Specifically, I'm using a magic link set up with Amplify on the web (which works well) and I'm trying to support it on iOS and Android with Flutter. It doesn't seem to be working but I'm not sure if that's because the library just doesn't support it yet or if I'm doing something wrong.

If it's not supported, do you have any idea when it might be added? It's a critical feature for me – if it's not imminent then I'll have to look into alternative options.

If it is supported, I'll raise a separate issue to see what's going on. In brief, I've have the app working with username and password login but when I change to "authenticationFlowType": "CUSTOM_AUTH" in amplifyconfiguration.dart and try to sign in I get an AMPLIFY_SIGNIN_FAILED error each time. I would expect to get a response with the next step being submitting the confirmation code from the magic link.

@Amplifiyer and the entire team. Congratulations and thanks for all of the hard work!

@pierceglennie When you say "magic link set up with Amplify" you mean the email link set up with Amplify CLI? If so, how exactly are you doing the routing in flutter?

To answer your question - We are working on finalizing the custom auth capabilities of amplify-flutter, so please stay tuned.

Sorry, I should have been clearer. The log in process on our website is:

  • User enters their email and requests a log in link. The link contains a one time log in code as a query parameter

  • When they click the link, we take them to a log in page which authenticates them using Amplify. Basically we call sign in with just the username (no password) and then respond to the custom auth challenge with the code from the email link. On the Cognito side, the verification of the code uses some custom lambda scripts

  • We also give people the option to log in with a password if they prefer and have one set up

The process is pretty much as described here, except we pass the code via the query string of the login link rather than requiring the customer to type it in: https://aws.amazon.com/blogs/mobile/implementing-passwordless-email-authentication-with-amazon-cognito/

For our Flutter app, we are looking to implement the same process for consistency (and since many customers don't have passwords). We have username and password log in working fine but it's the log in link process we're having issues with.

We can successfully request a log in link (this happens via our own API which sets the custom auth code on Cognito). We have also set up this link so it will open our app using universal links. Once it's opened our app, we can extract the code from the query string.

The only bit that we're struggling on is that the sign in method of the Amplify Flutter library requires the password (unlike the javascript library) which we don't have. On the iOS library, the docs recommend passing a dummy password to support this flow and then you'll get an Auth challenge as a response (and then you send the code). This doesn't seem to work with the Flutter library though, we just get a failure response.

We have tried changing the authentication method to "CUSTOM_AUTH" in the amplify configuration file by the way. However, this doesn't fix the issue (probably because it's not yet supported) and it also stops username/password log in from working.

Thanks for the great work on the library so far by the way!

The only bit that we're struggling on is that the sign in method of the Amplify Flutter library requires the password (unlike the javascript library) which we don't have. On the iOS library, the docs recommend passing a dummy password to support this flow and then you'll get an Auth challenge as a response (and then you send the code). This doesn't seem to work with the Flutter library though, we just get a failure response.

Any resolution on this?
We are looking to have a passwordless auth as well, and running into the same issues as you are...

I didn't find any resolution. I'm basically waiting in the hope that it gets added to the library at some point relatively soon.

I didn't find any resolution. I'm basically waiting in the hope that it gets added to the library at some point relatively soon.

I was able to do this, check out my answer here: https://stackoverflow.com/a/66463088/6559381

Thanks, that's good to see. I might try that out if it's not added to the official library in the next couple of months (it's not holding us back right now)

How to add Amplify endpoint to flutter app for the .apk release of the app?

I have been trying to make the .apk release of my flutter login app (which uses amplify as the backend) work but it gives out an error. The app works when I run it on an emulator or when my phone is connected to my laptop in developer mode. I have no clue where the endpoint needs to be set for the .apk release. Please help?
Below is the screenshot of the error popping up.
https://i.stack.imgur.com/DvFKo.jpg

@shouza1712 please create a new bug report in this repository to track this issue. This issue is meant for gathering feedback for early amplify-flutter development only.

Closing this issue since Amplify for flutter is in GA.