├── .gitignore
├── .metadata
├── LICENSE
├── README.md
├── android
├── .gitignore
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ └── gradle-wrapper.properties
├── settings.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── kotlin
│ └── com
│ └── pycampers
│ └── flutter_cognito_plugin
│ ├── Cognito.kt
│ ├── FlutterCognitoPlugin.kt
│ └── serializer.kt
├── example
├── .gitignore
├── .metadata
├── README.md
├── android
│ ├── .gitignore
│ ├── app
│ │ ├── build.gradle
│ │ └── src
│ │ │ ├── debug
│ │ │ └── AndroidManifest.xml
│ │ │ ├── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── kotlin
│ │ │ │ └── com
│ │ │ │ │ └── pycampers
│ │ │ │ │ └── flutter_cognito_plugin_example
│ │ │ │ │ └── MainActivity.kt
│ │ │ └── res
│ │ │ │ ├── drawable
│ │ │ │ └── launch_background.xml
│ │ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ └── values
│ │ │ │ └── styles.xml
│ │ │ └── profile
│ │ │ └── AndroidManifest.xml
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ └── gradle-wrapper.properties
│ └── settings.gradle
├── ios
│ ├── .gitignore
│ ├── Flutter
│ │ ├── AppFrameworkInfo.plist
│ │ ├── Debug.xcconfig
│ │ └── Release.xcconfig
│ ├── Podfile
│ ├── Podfile.lock
│ ├── Runner.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ └── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── xcschemes
│ │ │ └── Runner.xcscheme
│ ├── Runner.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ └── Runner
│ │ ├── AppDelegate.swift
│ │ ├── Assets.xcassets
│ │ ├── AppIcon.appiconset
│ │ │ ├── Contents.json
│ │ │ ├── Icon-App-1024x1024@1x.png
│ │ │ ├── Icon-App-20x20@1x.png
│ │ │ ├── Icon-App-20x20@2x.png
│ │ │ ├── Icon-App-20x20@3x.png
│ │ │ ├── Icon-App-29x29@1x.png
│ │ │ ├── Icon-App-29x29@2x.png
│ │ │ ├── Icon-App-29x29@3x.png
│ │ │ ├── Icon-App-40x40@1x.png
│ │ │ ├── Icon-App-40x40@2x.png
│ │ │ ├── Icon-App-40x40@3x.png
│ │ │ ├── Icon-App-60x60@2x.png
│ │ │ ├── Icon-App-60x60@3x.png
│ │ │ ├── Icon-App-76x76@1x.png
│ │ │ ├── Icon-App-76x76@2x.png
│ │ │ └── Icon-App-83.5x83.5@2x.png
│ │ └── LaunchImage.imageset
│ │ │ ├── Contents.json
│ │ │ ├── LaunchImage.png
│ │ │ ├── LaunchImage@2x.png
│ │ │ ├── LaunchImage@3x.png
│ │ │ └── README.md
│ │ ├── Base.lproj
│ │ ├── LaunchScreen.storyboard
│ │ └── Main.storyboard
│ │ ├── Info.plist
│ │ └── Runner-Bridging-Header.h
├── lib
│ └── main.dart
├── pubspec.lock
└── pubspec.yaml
├── flutter_cognito_plugin.iml
├── ios
├── .gitignore
├── Assets
│ └── .gitkeep
├── Classes
│ ├── Cognito.swift
│ ├── FlutterCognitoPlugin.h
│ ├── FlutterCognitoPlugin.m
│ ├── SwiftFlutterCognitoPlugin.swift
│ └── serializer.swift
└── flutter_cognito_plugin.podspec
├── lib
├── exception_serializer.dart
├── exceptions.dart
├── flutter_cognito_plugin.dart
└── models.dart
├── pubspec.lock
└── pubspec.yaml
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .dart_tool/
3 |
4 | .packages
5 | .pub/
6 |
7 | build/
8 |
9 | **/awsconfiguration.json
10 | .idea/
11 |
--------------------------------------------------------------------------------
/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: 0b8abb4724aa590dd0f429683339b1e045a1594d
8 | channel: stable
9 |
10 | project_type: plugin
11 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://www.jaaga.in/labs)
2 | [](https://pub.dartlang.org/packages/flutter_cognito_plugin)
3 |
4 | # Flutter Cognito Plugin
5 |
6 | An AWS Cognito plugin for flutter. Supports both iOS and Android.
7 |
8 | ## Installation
9 |
10 | First follow the regular flutter plugin installation on [Dart Pub](https://pub.dartlang.org/packages/flutter_cognito_plugin#-installing-tab-).
11 |
12 | _Make sure you have built the app once for both Android/iOS before continuing._
13 |
14 | ---
15 |
16 | Since this plugin uses the native AWS sdk, the installation is a little more involved.
17 |
18 | ### Android
19 |
20 | Add an `awsconfiguration.json` file to `android/app/src/main/res/raw/awsconfiguration.json`.
21 |
22 | This is what one should look like :-
23 |
24 | ```json
25 | {
26 | "IdentityManager": {
27 | "Default": {}
28 | },
29 | "CredentialsProvider": {
30 | "CognitoIdentity": {
31 | "Default": {
32 | "PoolId": "XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab",
33 | "Region": "XX-XXXX-X"
34 | }
35 | }
36 | },
37 | "CognitoUserPool": {
38 | "Default": {
39 | "PoolId": "XX-XXXX-X_abcd1234",
40 | "AppClientId": "XXXXXXXX",
41 | "AppClientSecret": "XXXXXXXXX",
42 | "Region": "XX-XXXX-X"
43 | }
44 | }
45 | }
46 | ```
47 |
48 | This plugin supports the amplify SDK for android and iOS,
49 | and the the amplify cli can be used to generate the `awsconfiguration.json` file.
50 |
51 | Just do `$ amplify init` from the `android` & `ios` folder of your app.
52 |
53 | ### iOS
54 |
55 | Run `$ pod init` from the `ios` folder of your app.
56 |
57 | Now, open `ios/Podfile`. Ensure ios version is set to a minimum of `9.0`.
58 |
59 | ```podspec
60 | platform :ios, '9.0'
61 | ```
62 |
63 | To add the `awsconfiguration.json` file to iOS module, you will unfortunately,
64 | need to open up your project in XCode.
65 |
66 | 1. Start Xcode
67 | 2. Click on ‘File > Open’
68 | 3. Select the `ios/Runner.xcworkspace` file.
69 |
70 | Now just drag-drop the `awsconfiguration.json` file, from `android/app/src/main/res/raw/awsconfiguration.json` to XCode Runner (Right next to `AppDelegate.swift`).
71 |
72 | [Here](https://i.imgur.com/tAXQuQ3.mp4) is a video.
73 |
74 | That should create a symlink to the file in the ios module, and bundle it into the final ios app.
75 |
76 | This way you won't need to maintain 2 config files.
77 |
78 | ## Hosted UI
79 |
80 | The [Hosted UI](https://docs.amplify.aws/sdk/auth/hosted-ui/q/platform/android) feature is needed for using Social login.
81 | Unfortunately, this requires you to modify native code in your app.
82 |
83 | First, add the following section to `android/app/src/main/res/raw/awsconfiguration.json` -
84 |
85 | (`"myapp://callback"` and `"myapp://signout"` are custom urls you can provide in the "App client settings" section of Cognito User Pools)
86 |
87 | ```
88 | {
89 | ...
90 |
91 | "Auth": {
92 | "Default": {
93 | "OAuth": {
94 | "WebDomain": "XXX.auth.ap-south-1.amazoncognito.com",
95 | "AppClientId": "XXXXXXXX",
96 | "AppClientSecret": "XXXXX"
97 | "SignInRedirectURI": "myapp://callback",
98 | "SignOutRedirectURI": "myapp://signout",
99 | "Scopes": ["email, "openid"]
100 | }
101 | }
102 | }
103 | }
104 | ```
105 |
106 | ### Android
107 |
108 | 1. Open your app's [`andorid/app/src/main/com/kotlin/.../MainActivity.kt`](example/android/app/src/main/kotlin/com/pycampers/flutter_cognito_plugin_example/MainActivity.kt)
109 | and replace `FlutterActivity()` by `CognitoPluginActivity("")`.
110 |
111 | Here's what it should look like -
112 |
113 | ```kotlin
114 | package ...
115 |
116 | import androidx.annotation.NonNull
117 | import com.pycampers.flutter_cognito_plugin.CognitoPluginActivity
118 | import io.flutter.embedding.engine.FlutterEngine
119 | import io.flutter.plugins.GeneratedPluginRegistrant
120 |
121 | class MainActivity : CognitoPluginActivity("myapp") {
122 | override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
123 | GeneratedPluginRegistrant.registerWith(flutterEngine);
124 | }
125 | }
126 | ```
127 |
128 | 2. Add the following to [`android/app/src/main/AndroidManifest.xml`](example/android/app/src/main/AndroidManifest.xml) -
129 |
130 | ```xml
131 |
132 |
133 | ...
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 | ```
148 |
149 | ### iOS
150 |
151 | 1. Open you apps's [`ios/Runner/AppDelegate.swift`](example/ios/Runner/AppDelegate.swift),
152 | and replace `FlutterAppDelegate` with `CognitoPluginAppDelegate`.
153 |
154 | Here's what it should look like -
155 |
156 | ```swift
157 | import Flutter
158 | import flutter_cognito_plugin
159 | import UIKit
160 |
161 | @UIApplicationMain
162 | @objc class AppDelegate: CognitoPluginAppDelegate {
163 | override func application(
164 | _ application: UIApplication,
165 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
166 | ) -> Bool {
167 | GeneratedPluginRegistrant.register(with: self)
168 | return super.application(application, didFinishLaunchingWithOptions: launchOptions)
169 | }
170 | }
171 | ```
172 |
173 | 2. Add the following to [`ios/Runner/Info.plist`](example/ios/Runner/Info.plist)
174 |
175 | ```
176 |
177 |
178 |
179 |
180 |
181 |
182 | CFBundleURLTypes
183 |
184 |
185 | CFBundleURLSchemes
186 |
187 | myapp
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 | ```
197 |
198 | ### Dart
199 |
200 | Once the native setup is complete, you can use the following in your flutter app to launch the Hosted UI -
201 |
202 | ```dart
203 | Cognito.showSignIn(
204 | identityProvider: "Cognito",
205 | scopes: ["email", "openid"],
206 | );
207 | ```
208 |
209 | ## Usage
210 |
211 | The plugin comes with a showcase app that will let you try all features --
212 | given that you setup the `awsconfiguration.json` correctly.
213 |
214 |
215 |
216 | It's present in the usual [`example`](https://github.com/scientifichackers/flutter_cognito_plugin/blob/master/example/lib/main.dart) directory
217 |
218 | ```
219 | $ git clone https://github.com/pycampers/flutter_cognito_plugin.git
220 | $ cd flutter_cognito_plugin/example
221 | $ flutter run
222 | ```
223 |
224 | ## AppSync
225 |
226 | You can use AWS AppSync GraphQL API using this plugin easily. Just pass in the query as a String, and the query variables!
227 |
228 | ```dart
229 | import 'dart:convert';
230 | import 'dart:io';
231 |
232 | import 'package:flutter_cognito_plugin/flutter_cognito_plugin.dart';
233 | import 'package:http/http.dart' as http;
234 |
235 |
236 | static Future