{"id":19839424,"url":"https://github.com/scientifichackers/flutter_cognito_plugin","last_synced_at":"2026-01-11T13:35:26.583Z","repository":{"id":54854500,"uuid":"172977636","full_name":"scientifichackers/flutter_cognito_plugin","owner":"scientifichackers","description":"An AWS cognito plugin for flutter","archived":false,"fork":false,"pushed_at":"2021-01-25T07:26:36.000Z","size":217,"stargazers_count":59,"open_issues_count":27,"forks_count":28,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-06T17:04:39.041Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scientifichackers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-27T19:36:19.000Z","updated_at":"2025-03-20T09:37:51.000Z","dependencies_parsed_at":"2022-08-14T04:50:35.696Z","dependency_job_id":null,"html_url":"https://github.com/scientifichackers/flutter_cognito_plugin","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scientifichackers%2Fflutter_cognito_plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scientifichackers%2Fflutter_cognito_plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scientifichackers%2Fflutter_cognito_plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scientifichackers%2Fflutter_cognito_plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scientifichackers","download_url":"https://codeload.github.com/scientifichackers/flutter_cognito_plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251932513,"owners_count":21667157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T12:22:24.030Z","updated_at":"2026-01-11T13:35:26.576Z","avatar_url":"https://github.com/scientifichackers.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Sponsor](https://img.shields.io/badge/Sponsor-jaaga_labs-red.svg?style=for-the-badge)](https://www.jaaga.in/labs)\n[![pub package](https://img.shields.io/pub/v/flutter_cognito_plugin.svg?style=for-the-badge)](https://pub.dartlang.org/packages/flutter_cognito_plugin)\n\n# Flutter Cognito Plugin\n\nAn AWS Cognito plugin for flutter. Supports both iOS and Android.\n\n## Installation\n\nFirst follow the regular flutter plugin installation on [Dart Pub](https://pub.dartlang.org/packages/flutter_cognito_plugin#-installing-tab-).\n\n_Make sure you have built the app once for both Android/iOS before continuing._\n\n---\n\nSince this plugin uses the native AWS sdk, the installation is a little more involved.\n\n### Android\n\nAdd an `awsconfiguration.json` file to `android/app/src/main/res/raw/awsconfiguration.json`.\n\nThis is what one should look like :-\n\n```json\n{\n    \"IdentityManager\": {\n        \"Default\": {}\n    },\n    \"CredentialsProvider\": {\n        \"CognitoIdentity\": {\n            \"Default\": {\n                \"PoolId\": \"XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab\",\n                \"Region\": \"XX-XXXX-X\"\n            }\n        }\n    },\n    \"CognitoUserPool\": {\n        \"Default\": {\n            \"PoolId\": \"XX-XXXX-X_abcd1234\",\n            \"AppClientId\": \"XXXXXXXX\",\n            \"AppClientSecret\": \"XXXXXXXXX\",\n            \"Region\": \"XX-XXXX-X\"\n        }\n    }\n}\n```\n\nThis plugin supports the amplify SDK for android and iOS,\nand the the amplify cli can be used to generate the `awsconfiguration.json` file.\n\nJust do `$ amplify init` from the `android` \u0026 `ios` folder of your app.\n\n### iOS\n\nRun `$ pod init` from the `ios` folder of your app.\n\nNow, open `ios/Podfile`. Ensure ios version is set to a minimum of `9.0`.\n\n```podspec\nplatform :ios, '9.0'\n```\n\nTo add the `awsconfiguration.json` file to iOS module, you will unfortunately,\nneed to open up your project in XCode.\n\n1. Start Xcode\n2. Click on ‘File \u003e Open’\n3. Select the `ios/Runner.xcworkspace` file.\n\nNow just drag-drop the `awsconfiguration.json` file, from `android/app/src/main/res/raw/awsconfiguration.json` to XCode Runner (Right next to `AppDelegate.swift`).\n\n[Here](https://i.imgur.com/tAXQuQ3.mp4) is a video.\n\nThat should create a symlink to the file in the ios module, and bundle it into the final ios app.\n\nThis way you won't need to maintain 2 config files.\n\n## Hosted UI\n\nThe [Hosted UI](https://docs.amplify.aws/sdk/auth/hosted-ui/q/platform/android) feature is needed for using Social login.\nUnfortunately, this requires you to modify native code in your app.\n\nFirst, add the following section to `android/app/src/main/res/raw/awsconfiguration.json` -\n\n(`\"myapp://callback\"` and `\"myapp://signout\"` are custom urls you can provide in the \"App client settings\" section of Cognito User Pools)\n\n```\n{\n  ...\n\n  \"Auth\": {\n    \"Default\": {\n      \"OAuth\": {\n        \"WebDomain\": \"XXX.auth.ap-south-1.amazoncognito.com\",\n        \"AppClientId\": \"XXXXXXXX\",\n        \"AppClientSecret\": \"XXXXX\"\n        \"SignInRedirectURI\": \"myapp://callback\",\n        \"SignOutRedirectURI\": \"myapp://signout\",\n        \"Scopes\": [\"email, \"openid\"]\n      }\n    }\n  }\n}\n```\n\n### Android\n\n1. 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)\n   and replace `FlutterActivity()` by `CognitoPluginActivity(\"\u003curl scheme\u003e\")`.\n\nHere's what it should look like -\n\n```kotlin\npackage ...\n\nimport androidx.annotation.NonNull\nimport com.pycampers.flutter_cognito_plugin.CognitoPluginActivity\nimport io.flutter.embedding.engine.FlutterEngine\nimport io.flutter.plugins.GeneratedPluginRegistrant\n\nclass MainActivity : CognitoPluginActivity(\"myapp\") {\n    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {\n        GeneratedPluginRegistrant.registerWith(flutterEngine);\n    }\n}\n```\n\n2. Add the following to [`android/app/src/main/AndroidManifest.xml`](example/android/app/src/main/AndroidManifest.xml) -\n\n```xml\n\u003cmanifest ...\u003e\n        \u003capplication ...\u003e\n            ...\n\n            \u003c!-- Add this section for AWS Cognito hosted UI--\u003e\n            \u003cintent-filter\u003e\n                \u003caction android:name=\"android.intent.action.VIEW\" /\u003e\n\n                \u003ccategory android:name=\"android.intent.category.DEFAULT\" /\u003e\n                \u003ccategory android:name=\"android.intent.category.BROWSABLE\" /\u003e\n\n                \u003cdata android:scheme=\"myapp\" /\u003e\n            \u003c/intent-filter\u003e\n\n        \u003c/application\u003e\n\u003c/manifest\u003e\n```\n\n### iOS\n\n1. Open you apps's [`ios/Runner/AppDelegate.swift`](example/ios/Runner/AppDelegate.swift),\n   and replace `FlutterAppDelegate` with `CognitoPluginAppDelegate`.\n\nHere's what it should look like -\n\n```swift\nimport Flutter\nimport flutter_cognito_plugin\nimport UIKit\n\n@UIApplicationMain\n@objc class AppDelegate: CognitoPluginAppDelegate {\n    override func application(\n        _ application: UIApplication,\n        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?\n    ) -\u003e Bool {\n        GeneratedPluginRegistrant.register(with: self)\n        return super.application(application, didFinishLaunchingWithOptions: launchOptions)\n    }\n}\n```\n\n2. Add the following to [`ios/Runner/Info.plist`](example/ios/Runner/Info.plist)\n\n```\n\u003cplist version=\"1.0\"\u003e\n\u003cdict\u003e\n    \u003c!-- YOUR OTHER PLIST ENTRIES HERE --\u003e\n\n    \u003c!-- ADD AN ENTRY TO CFBundleURLTypes for Cognito Auth --\u003e\n    \u003c!-- IF YOU DO NOT HAVE CFBundleURLTypes, YOU CAN COPY THE WHOLE BLOCK BELOW --\u003e\n    \u003ckey\u003eCFBundleURLTypes\u003c/key\u003e\n    \u003carray\u003e\n        \u003cdict\u003e\n            \u003ckey\u003eCFBundleURLSchemes\u003c/key\u003e\n            \u003carray\u003e\n                \u003cstring\u003emyapp\u003c/string\u003e\n            \u003c/array\u003e\n        \u003c/dict\u003e\n    \u003c/array\u003e\n\u003c/dict\u003e\n\u003c/array\u003e\n\n\u003c!-- ... --\u003e\n\u003c/dict\u003e\n```\n\n### Dart\n\nOnce the native setup is complete, you can use the following in your flutter app to launch the Hosted UI -\n\n```dart\nCognito.showSignIn(\n  identityProvider: \"Cognito\",\n  scopes: [\"email\", \"openid\"],\n);\n```\n\n## Usage\n\nThe plugin comes with a showcase app that will let you try all features --\ngiven that you setup the `awsconfiguration.json` correctly.\n\n\u003cimage src='https://i.imgur.com/5Lnl79O.png' height=400 /\u003e\n\nIt's present in the usual [`example`](https://github.com/scientifichackers/flutter_cognito_plugin/blob/master/example/lib/main.dart) directory\n\n```\n$ git clone https://github.com/pycampers/flutter_cognito_plugin.git\n$ cd flutter_cognito_plugin/example\n$ flutter run\n```\n\n## AppSync\n\nYou can use AWS AppSync GraphQL API using this plugin easily. Just pass in the query as a String, and the query variables!\n\n```dart\nimport 'dart:convert';\nimport 'dart:io';\n\nimport 'package:flutter_cognito_plugin/flutter_cognito_plugin.dart';\nimport 'package:http/http.dart' as http;\n\n\nstatic Future\u003cMap\u003e query(\n  String query,\n  Map\u003cString, dynamic\u003e variables,\n) async {\n  final tokens = await Cognito.getTokens();\n\n  final response = await http.post(\n    graphQLEndpoint,\n    headers: {\n      HttpHeaders.authorizationHeader: tokens.accessToken,\n      HttpHeaders.contentTypeHeader: ContentType.json.mimeType,\n    },\n    body: jsonEncode({\n      \"query\": query,\n      \"variables\": variables,\n    }),\n  );\n\n  if (response.statusCode == HttpStatus.ok) {\n    return jsonDecode(response.body);\n  }\n\n  print(\n    \"http request failed! { statusCode: ${response.statusCode}, body: ${response.body} }\",\n  );\n  return null;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscientifichackers%2Fflutter_cognito_plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscientifichackers%2Fflutter_cognito_plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscientifichackers%2Fflutter_cognito_plugin/lists"}