{"id":13573665,"url":"https://github.com/Clancey/simple_auth","last_synced_at":"2025-04-04T12:31:19.589Z","repository":{"id":37733952,"uuid":"136520641","full_name":"Clancey/simple_auth","owner":"Clancey","description":"The Simplest way to Authenticate in Flutter","archived":false,"fork":false,"pushed_at":"2023-04-02T21:09:48.000Z","size":583,"stargazers_count":354,"open_issues_count":63,"forks_count":108,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-28T11:11:56.598Z","etag":null,"topics":["authentication","dart","dart-library","flutter","flutter-plugin"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Clancey.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-06-07T19:14:50.000Z","updated_at":"2025-01-09T02:55:04.000Z","dependencies_parsed_at":"2024-01-05T21:04:31.968Z","dependency_job_id":null,"html_url":"https://github.com/Clancey/simple_auth","commit_stats":{"total_commits":191,"total_committers":32,"mean_commits":5.96875,"dds":"0.24083769633507857","last_synced_commit":"8dcfca6cd184e0b7962e12e45a10fa16265db27c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clancey%2Fsimple_auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clancey%2Fsimple_auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clancey%2Fsimple_auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clancey%2Fsimple_auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Clancey","download_url":"https://codeload.github.com/Clancey/simple_auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247174456,"owners_count":20896078,"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":["authentication","dart","dart-library","flutter","flutter-plugin"],"created_at":"2024-08-01T15:00:39.262Z","updated_at":"2025-04-04T12:31:19.569Z","avatar_url":"https://github.com/Clancey.png","language":"Dart","readme":"![Simple Auth](https://github.com/Clancey/simple_auth/blob/master/logo.png)\n[![Pub](https://img.shields.io/pub/v/simple_auth_flutter.svg)](https://pub.dartlang.org/packages/simple_auth_flutter)\nMost apps need to make API calls. Every API needs authentication, yet no developer wants to deal with authentication. Simple Auth embeds authentication into the API so you dont need to deal with it.\n\nThis is a port of [Clancey.SimpleAuth](https://github.com/clancey/simpleauth) for Dart and Flutter\n\nThe network/api part including the generator was based off of [Chopper by Hadrien Lejard](https://github.com/lejard-h/chopper)\n\n[![Join the chat at https://gitter.im/simple_auth/community](https://badges.gitter.im/simple_auth/community.svg)](https://gitter.im/simple_auth/community?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\niOS: [![Build status](https://build.appcenter.ms/v0.1/apps/788e968e-4f7d-4c90-a662-9877cee9d85a/branches/master/badge)](https://appcenter.ms)\n\nAndroid: [![Build status](https://build.appcenter.ms/v0.1/apps/339333fd-8d50-4694-ae98-eea0ec992d58/branches/master/badge)](https://appcenter.ms)\n\n## Providers\n\n### Current Built in Providers\n\n- Azure Active Directory\n- Amazon\n- Dropbox\n- Facebook\n- Github\n- Google\n- Linked In\n- Microsoft Live Connect\n- Keycloak\n- And of course any standard OAuth2/Basic Auth server.\n\n# Usage\n\n```dart\nvar api = new simpleAuth.GoogleApi(\n      \"google\", \"client_id\",clientSecret: \"clientSecret\",\n      scopes: [\n        \"https://www.googleapis.com/auth/userinfo.email\",\n        \"https://www.googleapis.com/auth/userinfo.profile\"\n      ]);\nvar request = new Request(HttpMethod.Get, \"https://www.googleapis.com/oauth2/v1/userinfo?alt=json\");\nvar userInfo = await api.send\u003cUserInfo, UserInfo\u003e(request);\n```\n\nThat's it! If the user is not logged in, they will automatically be prompted. If their credentials are cached from a previous session, the api call proceeds! Expired tokens even automatically refresh.\n\n# Flutter Setup\n\nCall `SimpleAuthFlutter.init();` in your Main.Dart. Now Simple Auth can automatically present your login UI\n\n# Redirect\n\nGoogle requires the following redirect: `com.googleusercontent.apps.YOUR_CLIENT_ID`\n\nSimple Auth by default uses SFSafari on iOS and Chrome Tabs on Android.\n\nThis means normal http redirects cannot work. You will need to register a custom scheme for your app as a redirect. For most providers, you can create whatever you want. i.e. `com.myapp.foo:/redirct`\n\n## Android Manifest\n\nyou would then add the following to your Android manifest\n\n```xml\n\u003cactivity android:name=\"clancey.simpleauth.simpleauthflutter.SimpleAuthCallbackActivity\" \u003e\n    \u003cintent-filter android:label=\"simple_auth\"\u003e\n        \u003caction android:name=\"android.intent.action.VIEW\" /\u003e\n        \u003ccategory android:name=\"android.intent.category.DEFAULT\" /\u003e\n        \u003ccategory android:name=\"android.intent.category.BROWSABLE\" /\u003e\n        \u003cdata android:scheme=\"com.myapp.foo\" /\u003e\n    \u003c/intent-filter\u003e\n\u003c/activity\u003e\n```\n\nFor instagram, the above won't work, as it will only accept redirect URIs that start with https. Add the following instead:\n\n```xml\n    \u003cactivity android:name=\"clancey.simpleauth.simpleauthflutter.SimpleAuthCallbackActivity\"\u003e\n\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=\"http\" /\u003e\n        \u003cdata android:scheme=\"https\" /\u003e\n        \u003cdata android:host=\"myflutterapp.com\" /\u003e\n      \u003c/intent-filter\u003e\n    \u003c/activity\u003e\n```\n\n## iOS \u0026 macOS\n\non iOS you need something like the following as your AppDelegate.m file under the Runner folder\n\n```objective-c\n#include \"AppDelegate.h\"\n#include \"GeneratedPluginRegistrant.h\"\n#import \u003cFlutter/Flutter.h\u003e\n#import \u003csimple_auth_flutter/SimpleAuthFlutterPlugin.h\u003e\n\n@implementation AppDelegate\n\n- (BOOL)application:(UIApplication *)application\n    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n  [GeneratedPluginRegistrant registerWithRegistry:self];\n  // Override point for customization after application launch.\n  return [super application:application didFinishLaunchingWithOptions:launchOptions];\n}\n\n- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary\u003cUIApplicationOpenURLOptionsKey,id\u003e *)options{\n    return [SimpleAuthFlutterPlugin checkUrl:url];\n}\n\n- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{\n    return [SimpleAuthFlutterPlugin checkUrl:url];\n}\n\n@end\n\n```\n\nOn macOS:\n\n```swift\nimport Cocoa\nimport FlutterMacOS\nimport simple_auth_flutter\n\n@NSApplicationMain\nclass AppDelegate: FlutterAppDelegate {\n  override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -\u003e Bool {\n    return true\n  }\n    \n    override func applicationDidFinishLaunching(_ notification: Notification) {\n        let appleEventManager:NSAppleEventManager = NSAppleEventManager.shared()\n        appleEventManager.setEventHandler(self, andSelector: #selector(AppDelegate.handleGetURLEvent(event:replyEvent:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))\n\n    }\n    \n    @objc func handleGetURLEvent(event: NSAppleEventDescriptor, replyEvent: NSAppleEventDescriptor) {\n        let urlString = event.paramDescriptor(forKeyword: AEKeyword(keyDirectObject))?.stringValue!\n        let url = URL(string: urlString!)!\n        SimpleAuthFlutterPlugin.check(url);\n    }\n}\n\n```\n\nFor iOS 11/macOS 10.15 and higher, you don't need to do anything else. On older versions the following is required in the info.plist\n\n```xml\n\t\u003ckey\u003eCFBundleURLTypes\u003c/key\u003e\n\t\u003carray\u003e\n\t\t\u003cdict\u003e\n\t\t\t\u003ckey\u003eCFBundleURLSchemes\u003c/key\u003e\n\t\t\t\u003carray\u003e\n\t\t\t\t\u003cstring\u003ecom.myapp.foo\u003c/string\u003e\n\t\t\t\u003c/array\u003e\n\t\t\t\u003ckey\u003eCFBundleURLName\u003c/key\u003e\n\t\t\t\u003cstring\u003emyappredirect\u003c/string\u003e\n\t\t\u003c/dict\u003e\n\t\u003c/array\u003e\n\n```\nNote, if you want to avoid Apples mandatory user consent dialog\n\n| \"foo\" Wants to use \"bar.com\" to Sign In |\n| - |\n|This allows the app and website to share information about you.|\n\nadd the lines above and set `FooAuthenticator.useSSO = false;` which will not use SFAuthenticationSession on iOS, and ASWebAuthenticationSession on macOS. This is the default behavior for the Keycloak provider.\n\n# Serialization\n\nJson objects will automatically serialize if you conform to [JsonSerializable](https://github.com/Clancey/simple_auth/blob/master/simple_auth/lib/src/jsonSerializable.dart)\n\nIf you use the generator and you objects have the factory `factory JsonSerializable.fromJson(Map\u003cString, dynamic\u003e json)` your api calls will automatically Serialize/Deserialize\n\nOr you can pass your own [Converter](https://github.com/Clancey/simple_auth/blob/master/simple_auth/lib/src/converter.dart) to the api and handle conversion yourself.\n\n# Generator\n\n### Dart\n\n```\npub run build_runner build\n```\n\n### flutter\n\n```\nflutter packages pub run build_runner build\n```\n\nAdd the following to your pubspec.yaml\n\n```yaml\ndev_dependencies:\n  simple_auth_generator:\n  build_runner: ^0.8.0\n```\n\nThe Generator is not required, however it will make things magical.\n\n```dart\n@GoogleApiDeclaration(\"GoogleTestApi\",\"client_id\",clientSecret: \"client_secret\", scopes: [\"TestScope\", \"Scope2\"])\nabstract class GoogleTestDefinition {\n  @Get(url: \"https://www.googleapis.com/oauth2/v1/userinfo?alt=json\")\n  Future\u003cResponse\u003cGoogleUser\u003e\u003e getCurrentUserInfo();\n}\n\n```\n\nwill generate a new Api for you that is easy to use!\n\n```dart\nvar api = new GoogleTestApi(\"google\");\nvar user = await api.getCurrentUserInfo();\n```\n\nFor more examples, check out the [example project](https://github.com/Clancey/simple_auth/tree/master/simple_auth_flutter_example/lib/api_definitions)\n\n# Contributor\n\n- Thanks for the logo made by [@iqbalhood](https://github.com/iqbalhood)\n\n# TODO\n\n- Add more documentation\n- Add native flutter providers for google\n","funding_links":[],"categories":["组件","Dart","Components","Auth [🔝](#readme)"],"sub_categories":["验证","身份验证","Auth"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FClancey%2Fsimple_auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FClancey%2Fsimple_auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FClancey%2Fsimple_auth/lists"}