You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Authorization Code Grant][authorizationCodeGrantSection], [Client Credentials Grant][clientCredentialsGrantSection] and [Resource Owner Password Grant][resourceOwnerPasswordGrantSection] flows, but more may be added in the future.
<summary>Click here to learn how to implement the imaginary functions mentioned above.</summary>
115
+
116
+
-----
117
+
118
+
Unfortunately, there's not a universal example for implementing the imaginary functions, `redirect` and `listen`, because different options exist for each platform.
119
+
120
+
For Flutter apps, there's two popular approaches:
121
+
1. Launch a browser using [url_launcher][] and listen for a redirect using [uni_links][].
122
+
```dart
123
+
if (await canLaunch(authorizationUrl.toString())) {
124
+
await launch(authorizationUrl.toString());
125
+
}
126
+
127
+
...
128
+
129
+
final linksStream = getLinksStream().listen((Uri uri) async {
130
+
if (uri.toString().startsWith(redirectUrl)) {
131
+
responseUrl = uri;
132
+
}
133
+
});
134
+
```
135
+
136
+
2. Launch a WebView inside the app and listen for a redirect using [webview_flutter][].
137
+
```dart
138
+
WebView(
139
+
javascriptMode: JavascriptMode.unrestricted,
140
+
initialUrl: authorizationUrl.toString(),
141
+
navigationDelegate: (navReq) {
142
+
if (navReq.url.startsWith(redirectUrl)) {
143
+
responseUrl = Uri.parse(navReq.url);
144
+
return NavigationDecision.prevent;
145
+
}
146
+
147
+
return NavigationDecision.navigate;
148
+
},
149
+
...
150
+
);
151
+
```
152
+
153
+
For Dart apps, the best approach depends on the available options for accessing a browser. In general, you'll need to launch the authorization URL through the client's browser and listen for the redirect URL.
0 commit comments