{"id":22706,"date":"2022-01-05T12:23:23","date_gmt":"2022-01-05T12:23:23","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/blog\/?p=22706"},"modified":"2024-06-03T05:27:09","modified_gmt":"2024-06-03T05:27:09","slug":"authentication-using-aws-amplify-in-flutter","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/blog\/authentication-using-aws-amplify-in-flutter","title":{"rendered":"How to Integrate Authentication using AWS Amplify in Flutter: Complete Guide"},"content":{"rendered":"<h2>Introduction: Integrate Authentication using AWS Amplify in Flutter<\/h2>\n<p>Have you ever got the client requirement of integrating <b>authentication using AWS Amplify in Flutter<\/b>? Are you stuck and figuring out where to start? Or, are you just a curious flutter enthusiast who wants to learn how to authenticate your flutter application using AWS amplify? If yes, then we are here to help you! Here is aws amplify tutorial where we will provide a complete guide to authenticate the flutter application using AWS amplify. We will cover both technical and theoretical sections. So, without further ado, let\u2019s get started!<\/p>\n<h2>What is AWS Amplify?<\/h2>\n<p>AWS Amplify authentication is a collection of tools, features, and libraries that helps to build and host web applications and mobile apps on AWS. Amplify supports various frameworks &#038; platforms like JavaScript, Vue, Next.Js, and mobile platforms like IOS, Android, Flutter, React Native, Ionic. AWS amplifies the used bundle of User Interface Components &#038; CLI (Command-line interface) to build app backend for web &#038; mobile apps.<\/p>\n<p>Cross-check the following prerequisites before developing and learning how to integrate <em>authentication using AWS amplify in Flutter<\/em>.<\/p>\n<h2>Pre-requisites<\/h2>\n<ul class=\"bullets text-left\">\n<li>Installed <a href=\"https:\/\/nodejs.org\/en\/download\/\" target=\"_blank\" rel=\"noopener\"><strong>NodeJS<\/strong><\/a> and <a href=\"https:\/\/www.npmjs.com\/get-npm\" target=\"_blank\" rel=\"noopener\" class=\"broken_link\"><strong>Node Package Manager<\/strong><\/a><\/li>\n<li>Install the latest version of <a href=\"https:\/\/flutter.dev\/docs\/get-started\/install\" target=\"_blank\" rel=\"noopener\"><strong>Flutter<\/strong><\/a><\/li>\n<li><a href=\"https:\/\/flutter.dev\/docs\/get-started\/editor?tab=androidstudio\" target=\"_blank\" rel=\"noopener\"><strong>Set Up your IDE<\/strong><\/a><\/li>\n<li>Installed Flutter Developer Preview of the Amplify CLI. If you don\u2019t have it installed on your system, use the below command<\/li>\n<\/ul>\n<pre>npm install -g @aws-amplify\/cli@flutter-preview<\/pre>\n<ul class=\"bullets text-left\">\n<li>An AWS account.<\/li>\n<\/ul>\n<p><strong>Note:<\/strong> <em><strong>The existing version of @aws-amplify\/cli won&#8217;t work; you might need to install the latest flutter-preview version.<\/strong><\/em><\/p>\n<h2>Install Dependencies<\/h2>\n<p>Here are a few dependencies that you need to authenticate your flutter application using AWS amplify. Just follow the instructions and commands to get it installed.<\/p>\n<h3>Import Flutter Amplify packages into your project inside the pubspec.yaml file<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Amplify-packages-300x94.png\" alt=\"Amplify packages\" width=\"300\" height=\"94\" class=\"aligncenter size-medium wp-image-22743\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Amplify-packages-300x94.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Amplify-packages-1024x320.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Amplify-packages-768x240.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Amplify-packages.png 1180w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<h3>Fetching the Amplify packages<\/h3>\n<pre>flutter pub get<\/pre>\n<h3>Verify the version of Amplify CLI<\/h3>\n<pre>amplify \u2013 version<\/pre>\n<p><strong><em>Note: The output of this command should have \u201c-flutter-preview\u201d appended to it. If not, run \u201cnpm install -g @aws-amplify\/cli@flutter-preview\u201d in the terminal.<\/em><\/strong><\/p>\n<p>So, after the installation and configuration, let\u2019s move further in our tutorial: Integrate Authentication using AWS Amplify in Flutter.<\/p>\n<p class=\"boxed bg--secondary\" style=\"border: 1px solid #c7c7c7; box-shadow: 0 0 40px rgba(0, 0, 0, 0.2);\"><strong><em><span style=\"font-size:22px; color:#000;\">Subside the project complexities!<\/span><br \/>\nAre you searching for Flutter developers with a great spectrum of knowledge? Struggles are real when you\u2019re dealing with a complex project. We are here to help you with your hustles. Get in touch with us today to <a href=\"https:\/\/www.bacancytechnology.com\/hire-flutter-developer\" target=\"_blank\" rel=\"noopener\">Hire Flutter Developer<\/a> with fundamental and advanced knowledge.<\/em><\/strong><\/p>\n<h2>Initialize and Configure Amplify<\/h2>\n<p>The next step is to connect to the AWS cloud, and for that, we need to initialize Amplify. Run the below command in your terminal.<\/p>\n<pre>amplify init<\/pre>\n<p>Your terminal will look as shown in the below image.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/How-to-Integrate-Authentication_Subimage1-1-min-300x175.png\" alt=\"Initialize and Configure Amplify\" width=\"300\" height=\"175\" class=\"aligncenter size-medium wp-image-22720\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/How-to-Integrate-Authentication_Subimage1-1-min-300x175.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/How-to-Integrate-Authentication_Subimage1-1-min-1024x598.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/How-to-Integrate-Authentication_Subimage1-1-min-768x448.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/How-to-Integrate-Authentication_Subimage1-1-min.png 1100w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Now use the command to configure the user for Flutter AWS.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Authentication-using-aws-amplify-in-Flutter-min-300x155.png\" alt=\"Authentication using aws amplify in Flutter\" width=\"300\" height=\"155\" class=\"aligncenter size-medium wp-image-22721\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Authentication-using-aws-amplify-in-Flutter-min-300x155.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Authentication-using-aws-amplify-in-Flutter-min-1024x529.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Authentication-using-aws-amplify-in-Flutter-min-768x397.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Authentication-using-aws-amplify-in-Flutter-min.png 1100w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Authentication-using-aws-amplify-in-Flutter-min-1-300x155.png\" alt=\"Authentication using aws amplify in Flutter\" width=\"300\" height=\"155\" class=\"aligncenter size-medium wp-image-22722\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Authentication-using-aws-amplify-in-Flutter-min-1-300x155.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Authentication-using-aws-amplify-in-Flutter-min-1-1024x529.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Authentication-using-aws-amplify-in-Flutter-min-1-768x397.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Authentication-using-aws-amplify-in-Flutter-min-1.png 1100w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Add-tags-min-300x154.png\" alt=\"Add tags\" width=\"300\" height=\"154\" class=\"aligncenter size-medium wp-image-22723\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Add-tags-min-300x154.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Add-tags-min-1024x524.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Add-tags-min-768x393.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Add-tags-min.png 1100w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Review-min-300x155.png\" alt=\"Review\" width=\"300\" height=\"155\" class=\"aligncenter size-medium wp-image-22724\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Review-min-300x155.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Review-min-1024x529.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Review-min-768x397.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Review-min.png 1100w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Authentication-using-aws-amplify-in-Flutter-min-2-300x152.png\" alt=\"Authentication using aws amplify in Flutter\" width=\"300\" height=\"152\" class=\"aligncenter size-medium wp-image-22725\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Authentication-using-aws-amplify-in-Flutter-min-2-300x152.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Authentication-using-aws-amplify-in-Flutter-min-2-1024x520.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Authentication-using-aws-amplify-in-Flutter-min-2-768x390.png 768w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/01\/Authentication-using-aws-amplify-in-Flutter-min-2.png 1100w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>This command will help to create a new user or set an already created user for the project.<\/p>\n<p>So far, we have successfully set up AWS Amplify in our project. Now let\u2019s proceed further and get our hands-on coding part. In the below sections, we will set up Sign In and Sign Up for the users with the help of Flutter AWS Cognito.<\/p>\n<p>Also Read: <a href=\"https:\/\/www.bacancytechnology.com\/blog\/email-authentication-using-firebase-auth-and-flutter#4\" target=\"_blank\" rel=\"noopener\">Email and Password Authentication using Firebase Auth + Flutter<\/a><\/p>\n<h2>What is AWS Cognito?<\/h2>\n<p>Amazon Cognito is a simple and secure service that helps to add user authentication without much hustle to your mobile and web apps. AWS Cognito also supports social sign-in methods such as Facebook, Google, Amazon, and an enterprise identity provider SAML or Open ID Connect. This Amplify category has built-in support for the AWS Cognito.<\/p>\n<p>AWS Cognito has smoothened the application experience without worrying about building, scaling, and securing.<\/p>\n<p>AWS Cognito also enables us to sync data across the device so that users switch to a new or another device their experience remains consistent.<\/p>\n<p><strong>Prerequisites<\/strong><\/p>\n<ul class=\"bullets text-left\">\n<li>A Flutter application with Flutter SDK \u22651.20<\/li>\n<li>Amplify libraries installed as mentioned in the above section.<\/li>\n<\/ul>\n<h2>Add Auth via Amplify CLI<\/h2>\n<p>Run the below command in the terminal to start using flutter amplify auth in the project.<\/p>\n<pre>amplify add auth<\/pre>\n<p>You\u2019ll be prompted with a few questions to configure the auth preferences; just select the defaults,<\/p>\n<pre>? Do you want to use the default authentication and security configuration? `Default  configuration` \r\n? How do you want users to be able to sign in? \r\n`Username` \r\n? Do you want to configure advanced settings?  \r\n`No, I am done`<\/pre>\n<p>We need to push all the changes we have made after the auth configuration has been set. For pushing these changes, run the below command.<\/p>\n<pre>amplify push<\/pre>\n<h2>Integrate Auth to Sign Up and Sign In<\/h2>\n<p>Now, it\u2019s time to integrate Auth into our codebase finally. I hope the authentication using AWS amplify Flutter auth was understandable so far.<\/p>\n<h3>Sign Up<\/h3>\n<p>Implement AWS API calls like we used to do in Firebase Auth.<\/p>\n<pre>try {\r\n   Map<String, dynamic> userAttributes = {\r\n     \"email\": emailController.text,\r\n     \"phone_number\": phoneController.text,\r\n     \/\/ additional attributes as needed\r\n   };\r\n   SignUpResult res = await Amplify.Auth.signUp(\r\n       username: \"myusername\",\r\n       password: \"mysupersecurepassword\",\r\n       options: CognitoSignUpOptions(\r\n           userAttributes: userAttributes\r\n       ));\r\n } on AuthError\r\n catch (e) {\r\n   print(e);\r\n }<\/pre>\n<p>Now, the user will be confirmed. For that, a confirmation code will be sent to the email address of the user. You need to create a separate UI for the confirmation code as the user has to enter the code received in his\/her email and will pass it to the confirm Sign-up call.<\/p>\n<pre>try {\r\n   SignUpResult res = await Amplify.Auth.confirmSignUp(\r\n       username: \"myusername\",\r\n       confirmationCode: \"123456\"\r\n   );\r\n } on AuthError catch (e) {\r\n   print(e);\r\n }\r\n<\/pre>\n<p>Upon the successful completion of the signup flow, you can see Confirm sign-up Succeed message on the terminal.<\/p>\n<h3>Sign In<\/h3>\n<p>In the Sign-In UI, Part implements this API call.<\/p>\n<pre>try {\r\n   SignInResult res = await Amplify.Auth.signIn(\r\n     username: usernameController.text.trim(),\r\n     password: passwordController.text.trim(),\r\n   );\r\n } on AuthError catch (e) {\r\n   print(e);\r\n }\r\n<\/pre>\n<p>Upon the successful completion of the sign-in flow, you can see the Sign in a Succeeded message on the terminal.<\/p>\n<h2>Conclusion<\/h2>\n<p>So, this was about how to implement authentication using AWS amplify in Flutter. I hope the blog has helped you the way you expected. For more such flutter tutorials, feel free to visit the Flutter tutorials page where you can clone the github repository and play around with the code. We always appreciate the feedback.<\/p>\n<p>If you are already convinced and looking for assistance to integrate authentication using AWS Flutter, connect with us today. Being the renowned <a href=\"https:\/\/www.bacancytechnology.com\/flutter-app-development\" target=\"_blank\" rel=\"noopener\">Flutter app development company<\/a>, we can easy your way to play store and app store with the feature-loaded enterprise-grade mobile app without technical headaches.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: Integrate Authentication using AWS Amplify in Flutter Have you ever got the client requirement of integrating authentication using AWS Amplify in Flutter? Are you stuck and figuring out where to start? Or, are you just a curious flutter enthusiast who wants to learn how to authenticate your flutter application using AWS amplify? If yes, [&hellip;]<\/p>\n","protected":false},"author":171,"featured_media":22716,"comment_status":"open","ping_status":"open","sticky":false,"template":"blog-new-template.php","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"_lmt_disableupdate":"no","_lmt_disable":"","footnotes":""},"categories":[1200],"tags":[],"coauthors":[2425],"class_list":["post-22706","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-flutter"],"acf":[],"modified_by":"Chandresh Patel","_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/posts\/22706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/users\/171"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/comments?post=22706"}],"version-history":[{"count":0,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/posts\/22706\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/media\/22716"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=22706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=22706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=22706"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/coauthors?post=22706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}