dart-lang / tools

This repository is home to tooling related Dart packages.
BSD 3-Clause "New" or "Revised" License
30 stars 24 forks source link

Unclear documentation #366

Open RoarGronmo opened 3 years ago

RoarGronmo commented 3 years ago

Referencing to the expanding part of 'Readme' in https://pub.dev/packages/oauth2

Could you please referase this section so the code works...

 There is not a universal example for implementing redirect and listen, because different options exist for each platform.

For Flutter apps, there's two popular approaches:

Launch a browser using url_launcher and listen for a redirect using uni_links.

  if (await canLaunch(authorizationUrl.toString())) {
    await launch(authorizationUrl.toString()); }

  // ------- 8< -------

  final linksStream = getLinksStream().listen((Uri uri) async {
   if (uri.toString().startsWith(redirectUrl)) {
     responseUrl = uri;
   }
 });
Launch a WebView inside the app and listen for a redirect using webview_flutter.

  WebView(
    javascriptMode: JavascriptMode.unrestricted,
    initialUrl: authorizationUrl.toString(),
    navigationDelegate: (navReq) {
      if (navReq.url.startsWith(redirectUrl)) {
        responseUrl = Uri.parse(navReq.url);
        return NavigationDecision.prevent;
      }
      return NavigationDecision.navigate;
    },
    // ------- 8< -------
  );
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.

It is unclear where theese two section should go, and how is linksStream used ?

Muhesh7 commented 2 years ago

It's basically two different ways of Sending Authorization Request to the Authentication Server and Receiving the code back.