{"id":16783861,"url":"https://github.com/testeurmaniak/flutter_web_twitch_auth","last_synced_at":"2025-04-10T22:24:04.830Z","repository":{"id":110329804,"uuid":"340740717","full_name":"TesteurManiak/flutter_web_twitch_auth","owner":"TesteurManiak","description":"Example to illustrate how to implement an OAuth2 authentication flow in Flutter Web.","archived":false,"fork":false,"pushed_at":"2021-09-12T12:23:32.000Z","size":78,"stargazers_count":14,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"use-external-win","last_synced_at":"2025-03-24T19:21:57.616Z","etag":null,"topics":["authentication","flutter","flutter-web","twitch"],"latest_commit_sha":null,"homepage":"https://itnext.io/flutter-web-oauth-authentication-through-external-window-d890a7ff6463","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TesteurManiak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2021-02-20T19:53:50.000Z","updated_at":"2024-10-23T09:10:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"f5b034b3-7611-423e-9d85-cbf410c6d9d0","html_url":"https://github.com/TesteurManiak/flutter_web_twitch_auth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TesteurManiak%2Fflutter_web_twitch_auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TesteurManiak%2Fflutter_web_twitch_auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TesteurManiak%2Fflutter_web_twitch_auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TesteurManiak%2Fflutter_web_twitch_auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TesteurManiak","download_url":"https://codeload.github.com/TesteurManiak/flutter_web_twitch_auth/tar.gz/refs/heads/use-external-win","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248307250,"owners_count":21081814,"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","flutter","flutter-web","twitch"],"created_at":"2024-10-13T07:52:31.855Z","updated_at":"2025-04-10T22:24:04.814Z","avatar_url":"https://github.com/TesteurManiak.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flutter_web_twitch_auth\n\nA Flutter Web project to illustrate OAuth2 authentication flow using Twitch's API.\n\nThe project on this branch is using an external popup window to manage the login with Twitch.\n\n## Getting Started\n\nTo grab the response code in the callback URL I've added a `static.html` page in the `web/` folder. Its purpose is to send a message containing the URL with the access token to the parent window which would be the initial window of the Flutter application.\n\n```html\n\u003c!doctype html\u003e\n\u003chtml lang=\"en\"\u003e\n\n\u003chead\u003e\n    \u003cmeta charset=\"utf-8\"\u003e\n    \u003ctitle\u003eConnexion Succeeded\u003c/title\u003e\n    \u003cmeta name=\"description\"\n        content=\"Simple, quick, standalone responsive placeholder without any additional resources\"\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\"\u003e\n\u003c/head\u003e\n\n\u003cbody\u003e\n\u003c/body\u003e\n\u003cscript\u003e\n    window.opener.postMessage(window.location.href, '*');\n\u003c/script\u003e\n\n\u003c/html\u003e\n```\n\nAs for the Flutter code I've added a listener for incoming message to trigger the login when received a correct response.\n\n```dart\n// Listen to message send with `postMessage`.\nhtml.window.onMessage.listen((event) {\n  // The event contains the token which means the user is connected.\n  if (event.data.toString().contains('access_token=')) {\n    _login(event.data);\n  }\n});\n```\n\nAlso opening the login page in an external window and using our `static.html` page as the redirect_uri.\n\n```dart\n// Open the Twitch authentication page.\nWidgetsBinding.instance.addPostFrameCallback((_) {\n  final currentUri = Uri.base;\n  final redirectUri = Uri(\n    host: currentUri.host,\n    scheme: currentUri.scheme,\n    port: currentUri.port,\n    path: '/static.html',\n  );\n  final authUrl =\n    'https://id.twitch.tv/oauth2/authorize?response_type=token\u0026client_id=$clientId\u0026redirect_uri=$redirectUri\u0026scope=viewing_activity_read';\n  \n  // Keeping a reference to the popup window so you can close it after login is completed\n  _popupWin = html.window.open(\n    authUrl, \"Twitch Auth\", \"width=800, height=900, scrollbars=yes\");\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftesteurmaniak%2Fflutter_web_twitch_auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftesteurmaniak%2Fflutter_web_twitch_auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftesteurmaniak%2Fflutter_web_twitch_auth/lists"}