{"id":13550374,"url":"https://github.com/LinusU/flutter_web_auth","last_synced_at":"2025-04-03T00:33:53.851Z","repository":{"id":34299568,"uuid":"175845663","full_name":"LinusU/flutter_web_auth","owner":"LinusU","description":"Flutter plugin for authenticating a user with a web service","archived":false,"fork":false,"pushed_at":"2024-10-07T16:12:36.000Z","size":9994,"stargazers_count":201,"open_issues_count":42,"forks_count":195,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-31T03:06:15.374Z","etag":null,"topics":["flutter-plugin","hacktoberfest","oauth2","sfauthenticationsession"],"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/LinusU.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-15T15:27:00.000Z","updated_at":"2025-03-27T19:28:28.000Z","dependencies_parsed_at":"2024-01-16T18:57:59.192Z","dependency_job_id":"9a094d51-fa74-4f2d-8d02-f9c884ac7edf","html_url":"https://github.com/LinusU/flutter_web_auth","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinusU%2Fflutter_web_auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinusU%2Fflutter_web_auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinusU%2Fflutter_web_auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinusU%2Fflutter_web_auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LinusU","download_url":"https://codeload.github.com/LinusU/flutter_web_auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246916733,"owners_count":20854511,"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":["flutter-plugin","hacktoberfest","oauth2","sfauthenticationsession"],"created_at":"2024-08-01T12:01:32.303Z","updated_at":"2025-04-03T00:33:48.825Z","avatar_url":"https://github.com/LinusU.png","language":"Dart","funding_links":[],"categories":["Dart"],"sub_categories":[],"readme":"# Web Auth for Flutter\n\nA Flutter plugin for authenticating a user with a web service, even if the web service is run by a third party. Most commonly used with OAuth2, but can be used with any web flow that can redirect to a custom scheme.\n\nIn the background, this plugin uses [`ASWebAuthenticationSession`][ASWebAuthenticationSession] on iOS 12+ and macOS 10.15+, [`SFAuthenticationSession`][SFAuthenticationSession] on iOS 11, [Chrome Custom Tabs][Chrome Custom Tabs] on Android and opens a new window on Web. You can build it with iOS 8+, but it is currently only supported by iOS 11 or higher.\n\n[ASWebAuthenticationSession]: https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsession\n[SFAuthenticationSession]: https://developer.apple.com/documentation/safariservices/sfauthenticationsession\n[Chrome Custom Tabs]: https://developer.chrome.com/multidevice/android/customtabs\n\n| **iOS**                | **Android**                    |\n| ---------------------- | ------------------------------ |\n| ![iOS](screen-ios.gif) | ![Android](screen-android.gif) |\n\n| **macOS**                  |\n| -------------------------- |\n| ![macOS](screen-macos.gif) |\n\n## Usage\n\nTo authenticate against your own custom site:\n\n```dart\nimport 'package:flutter_web_auth/flutter_web_auth.dart';\n\n// Present the dialog to the user\nfinal result = await FlutterWebAuth.authenticate(url: \"https://my-custom-app.com/connect\", callbackUrlScheme: \"my-custom-app\");\n\n// Extract token from resulting url\nfinal token = Uri.parse(result).queryParameters['token']\n```\n\nTo authenticate the user using Google's OAuth2:\n\n```dart\nimport 'package:flutter_web_auth/flutter_web_auth.dart';\n\nimport 'dart:convert' show jsonDecode;\nimport 'package:http/http.dart' as http;\n\n// App specific variables\nfinal googleClientId = 'XXXXXXXXXXXX-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com';\nfinal callbackUrlScheme = 'com.googleusercontent.apps.XXXXXXXXXXXX-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';\n\n// Construct the url\nfinal url = Uri.https('accounts.google.com', '/o/oauth2/v2/auth', {\n  'response_type': 'code',\n  'client_id': googleClientId,\n  'redirect_uri': '$callbackUrlScheme:/',\n  'scope': 'email',\n});\n\n// Present the dialog to the user\nfinal result = await FlutterWebAuth.authenticate(url: url.toString(), callbackUrlScheme: callbackUrlScheme);\n\n// Extract code from resulting url\nfinal code = Uri.parse(result).queryParameters['code'];\n\n// Construct an Uri to Google's oauth2 endpoint\nfinal url = Uri.https('www.googleapis.com', 'oauth2/v4/token');\n\n// Use this code to get an access token\nfinal response = await http.post(url, body: {\n  'client_id': googleClientId,\n  'redirect_uri': '$callbackUrlScheme:/',\n  'grant_type': 'authorization_code',\n  'code': code,\n});\n\n// Get the access token from the response\nfinal accessToken = jsonDecode(response.body)['access_token'] as String;\n```\n\n**Note:** To use multiple scopes with Google, you need to encode them as a single string, separated by spaces. For example, `scope: 'email https://www.googleapis.com/auth/userinfo.profile'`. Here is [a list of all supported scopes](https://developers.google.com/identity/protocols/oauth2/scopes).\n\n## Setup\n\nSetup works as for any Flutter plugin, expect the Android and Web caveats outlined below:\n\n### Android\n\nIn order to capture the callback url, the following `activity` needs to be added to your `AndroidManifest.xml`. Be sure to relpace `YOUR_CALLBACK_URL_SCHEME_HERE` with your actual callback url scheme.\n\n```xml\n\u003cmanifest\u003e\n  \u003capplication\u003e\n\n    \u003cactivity android:name=\"com.linusu.flutter_web_auth.CallbackActivity\" android:exported=\"true\"\u003e\n      \u003cintent-filter android:label=\"flutter_web_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=\"YOUR_CALLBACK_URL_SCHEME_HERE\" /\u003e\n      \u003c/intent-filter\u003e\n    \u003c/activity\u003e\n\n  \u003c/application\u003e\n\u003c/manifest\u003e\n```\n\n### Web\n\nOn the Web platform an endpoint needs to be created that captures the callback URL and sends it to the application using the JavaScript `postMessage()` method. In the `./web` folder of the project, create an HTML file with the name e.g. `auth.html` with content:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003ctitle\u003eAuthentication complete\u003c/title\u003e\n\u003cp\u003eAuthentication is complete. If this does not happen automatically, please\nclose the window.\n\u003cscript\u003e\n  window.opener.postMessage({\n    'flutter-web-auth': window.location.href\n  }, window.location.origin);\n  window.close();\n\u003c/script\u003e\n```\n\nRedirection URL passed to the authentication service must be the same as the URL on which the application is running (schema, host, port if necessary) and the path must point to created HTML file, `/auth.html` in this case. The `callbackUrlScheme` parameter of the `authenticate()` method does not take into account, so it is possible to use a schema for native platforms in the code.\n\nFor the Sign in with Apple in web_message response mode, postMessage from https://appleid.apple.com is also captured, and the authorization object is returned as a URL fragment encoded as a query string (for compatibility with other providers).\n\n## Troubleshooting\n\nWhen you use this package for the first time, there are some problems you may have. These are some of the common solutions\n\n### Troubleshooting `callbackUrlScheme`\n\n- `callbackUrlScheme` must be a valid schema string or else this wont work.\n- A valid RFC 3986 URL scheme must consist of \"a letter and followed by any combination of letters, digits, plus (\"+\"), period (\".\"), or hyphen (\"-\").\"\n- scheme = ALPHA *( ALPHA / DIGIT / \"+\" / \"-\" / \".\" )\n- This means you can not use underscore \"_\", space \" \" or uppercase \"ABCDEF...\". You can not also start with a number. See [RFC3986#page-17](https://www.rfc-editor.org/rfc/rfc3986#page-17)\n- examples of VALID  `callbackUrlScheme` are `callback-scheme`, `another.scheme`, `examplescheme`\n- examples of INVALID  `callbackUrlScheme` are `callback_scheme`,`1another.scheme`, `exampleScheme`\n\n### Troubleshooting Flutter App\n\n- You have to tell the `FlutterWebAuth.authenticate` function what your `callbackUrlScheme` is.\n- Example if your `callbackUrlScheme` is  `valid-callback-scheme`, your dart code will look like\n\n    ```dart\n    import 'package:flutter_web_auth/flutter_web_auth.dart';\n\n    // Present the dialog to the user\n    final result = await FlutterWebAuth.authenticate(url: \"https://my-custom-app.com/connect\", callbackUrlScheme: \"valid-callback-scheme\");\n    ```\n\n### Troubleshooting Android\n\n- You are required to update your `AndroidManifest.xml` to include the `com.linusu.flutter_web_auth.CallbackActivity` activity something like\n\n    ```xml\n    \u003cmanifest\u003e\n      \u003capplication\u003e\n\n        \u003c!-- add the com.linusu.flutter_web_auth.CallbackActivity activity --\u003e\n        \u003cactivity android:name=\"com.linusu.flutter_web_auth.CallbackActivity\" android:exported=\"true\"\u003e\n          \u003cintent-filter android:label=\"flutter_web_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=\"YOUR_CALLBACK_URL_SCHEME_HERE\" /\u003e\n          \u003c/intent-filter\u003e\n        \u003c/activity\u003e\n\n      \u003c/application\u003e\n    \u003c/manifest\u003e\n    ```\n\n- Example of valid `AndroidManifest.xml` with VALID `callbackUrlScheme`. in the example below `valid-callback-scheme` is our `callbackUrlScheme`\n\n    ```xml\n    \u003cmanifest\u003e\n      \u003capplication\u003e\n\n        \u003cactivity android:name=\"com.linusu.flutter_web_auth.CallbackActivity\" android:exported=\"true\"\u003e\n          \u003cintent-filter android:label=\"flutter_web_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=\"valid-callback-scheme\" /\u003e\n          \u003c/intent-filter\u003e\n        \u003c/activity\u003e\n\n      \u003c/application\u003e\n    \u003c/manifest\u003e\n    ```\n\n- If you are targeting S+ (version 31 and above) you need to provide an explicit value for `android:exported`. If you followed earlier installation instructions this was not included. Make sure that you add `android:exported=\"true\"` to the `com.linusu.flutter_web_auth.CallbackActivity` activity in your `AndroidManifest.xml` file.\n\n    ```diff\n    - \u003cactivity android:name=\"com.linusu.flutter_web_auth.CallbackActivity\"\u003e\n    + \u003cactivity android:name=\"com.linusu.flutter_web_auth.CallbackActivity\" android:exported=\"true\"\u003e\n    ```\n\n### Troubleshooting OAuth redirects\n\n- Your OAuth Provider must redirect to the valid  `callbackUrlScheme` + `://`. This mean if your  `callbackUrlScheme` is `validscheme`, your OAuth Provider must redirect to `validscheme://`\n- Example with `php`\n    ```php\n    \u003c?php\n\n    header(\"Location: validscheme://?data1=value1\u0026data2=value2\");\n    ```\n\n### Troubleshooting HTML redirects\n\n- If you are using HTML hyperlinks, it must be a valid `callbackUrlScheme` + `://`. This mean if your `callbackUrlScheme` is `customappname`, your html hyperlink should be `customappname://`\n- example with `HTML`\n\n    ```html\n    \u003ca href=\"customappname://?data1=value1\u0026data2=value2\"\u003eGo Back to App\u003c/a\u003e\n    ```\n\n### Troubleshooting passing data to app\n\n- You can pass data back to your app by adding GET query parameters. This means by adding name=value type of data after your `callbackUrlScheme` + `://` + `?`\n- example to pass `access-token` to your app a valid url for that could be\n\n    ```text\n    my-callback-schema://?access-token=jdu9292s\n    ```\n\n- You can pass multipe data by concatenating with `\u0026`\n\n    ```text\n    my-callback-schema://?data1=value1\u0026data2=value2\n    ```\n\n- example to pass `access-token` and `user_id` to your app a valid url for that could be\n\n    ```text\n    my-callback-schema://?access-token=jdu9292s\u0026user_id=23\n    ```\n\n- You can get the data in your app by using `Uri.parse(result).queryParameters`\n\n    ```dart\n    // Present the dialog to the user\n    final result = await FlutterWebAuth.authenticate(url: \"https://my-custom-app.com/connect\", callbackUrlScheme: \"valid-callback-scheme\");\n    // Extract token from resulting url\n    String accessToken = Uri.parse(result).queryParameters['access-token'];\n    String userId = Uri.parse(result).queryParameters['user_id'];\n    ```\n\n### Cannot open keyboard on iOS\n\nThis seems to be a bug in `ASWebAuthenticationSession`, and no work around have been found. Please see [issue #120](https://github.com/LinusU/flutter_web_auth/issues/120) for more info.\n\n### Error on macOS if Chrome is default browser\n\nThis seems to be a bug in `ASWebAuthenticationSession`, and no work around have been found. Please see [issue #136](https://github.com/LinusU/flutter_web_auth/issues/136) for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLinusU%2Fflutter_web_auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLinusU%2Fflutter_web_auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLinusU%2Fflutter_web_auth/lists"}