xamarin / Xamarin.Auth

Xamarin.Auth
Apache License 2.0
541 stars 351 forks source link

WKWebViewNavigationDelegate : Support code flow #435

Open friendly-tech opened 4 years ago

friendly-tech commented 4 years ago

Allow usage of WKWebView with authorization code flow.

When setting the switch WebViewConfiguration.IOS.IsUsingWKWebView = true, the redirect url once hit just stays on the screen and does nothing.

WKWebViewNavigationDelegate seems to only support access tokens via the redirect url and doesnt do the same logic as UIWebView does

public override void DecidePolicy(
        WKWebView webView,
        WKNavigationAction navigationAction,
        Action<WKNavigationActionPolicy> decisionHandler)
      {
        Uri uri = new Uri(webView.Url.AbsoluteString);
        string fragment = uri.Fragment;
        if (fragment.Contains("access_token") || fragment.Contains("state") || (fragment.Contains("expires_in") || fragment.Contains("error")))
          this.controller.authenticator.OnSucceeded(new Account("", (IDictionary<string, string>) new Dictionary<string, string>(WebEx.FormDecode(uri.Fragment))));
        else if (fragment.Contains("code"))
          throw new NotImplementedException("code - Explicit/Server");
        decisionHandler(WKNavigationActionPolicy.Allow);
      }

It should call into this.controller.authenticator.OnPageLoaded(url); and eventually RequestAccessTokenAsync the same as the UIWebView does and not just do nothing like it currently does.

friendly-tech commented 4 years ago

https://github.com/xamarin/Xamarin.Auth/issues/411

https://github.com/xamarin/Xamarin.Auth/pull/413