@@ -128,15 +128,16 @@ because different options exist for each platform.
128
128
For Flutter apps, there's two popular approaches:
129
129
130
130
1 . Launch a browser using [ url_launcher] [ ] and listen for a redirect using
131
- [ uni_links ] [ ] .
131
+ [ app_links ] [ ] .
132
132
133
133
``` dart
134
134
if (await canLaunch(authorizationUrl.toString())) {
135
135
await launch(authorizationUrl.toString()); }
136
136
137
137
// ------- 8< -------
138
138
139
- final linksStream = getLinksStream().listen((Uri uri) async {
139
+ final appLinks = AppLinks();
140
+ final linksStream = appLinks.uriLinkStream.listen((Uri uri) async {
140
141
if (uri.toString().startsWith(redirectUrl)) {
141
142
responseUrl = uri;
142
143
}
@@ -161,6 +162,45 @@ For Flutter apps, there's two popular approaches:
161
162
);
162
163
```
163
164
165
+
166
+ 1. To handle redirect on Flutter Web you would need to add a html file to the web folder with some
167
+ additional JS code to handle the redirect back to the app (in this example the code will be saved
168
+ and passed through localStorage).
169
+
170
+ ```html
171
+ <!DOCTYPE html>
172
+ <html>
173
+ <head>
174
+ <meta charset="UTF-8" />
175
+ <title>OAuth Callback</title>
176
+ </head>
177
+ <body>
178
+ <script>
179
+ const urlParams = new URLSearchParams(window.location.search);
180
+ const code = urlParams.get('code');
181
+
182
+ // Store them in localStorage (or sessionStorage).
183
+ if (code) {
184
+ localStorage.setItem('oauth_code', code);
185
+ }
186
+
187
+ window.location.replace('/#/');
188
+ </script>
189
+ </body>
190
+ </html>
191
+ ```
192
+
193
+ After redirect to the application the code can be extracted and processed using the dart.html
194
+ package
195
+
196
+ ```dart
197
+ import 'dart:html' as html;
198
+ ...
199
+ if(html.window.localStorage.containsKey('oauth_code')
200
+ code = html.window.localStorage.remove('oauth_code')
201
+ ...
202
+ ```
203
+
164
204
For Dart apps, the best approach depends on the available options for accessing
165
205
a browser. In general, you'll need to launch the authorization URL through the
166
206
client's browser and listen for the redirect URL.
0 commit comments