Is there any way to intercept redirect requests in Android WebView? shouldInterceptRequest(WebView,WebResourceRequest) does not seem to get called!
I wanted to automatically catch token expiration in all web view requests by:
- Issuing a redirect rather than a 401 from the server
- Using shouldOverrideUrlLoading() to invoke AppAuth where a login is necessary
- Using shouldInterceptRequest to bounce back to the original URL with a refreshed token where a login is not necessary
Item 2 is working fine, but item 3 is failing spectacularly since shouldInterceptRequest seems not to be called for redirects, which seems really wrong -- particularly since this is not documented and the WebResourceRequest API would lead one to believe that one can even check whether the request is a redirect.
I'd happily respond to 401's instead of using redirects -- but I see no way to retry the request "in situ" with an updated token, unless the request happens to be a top-level page request.
I suppose I could try the old "in page" redirect instead of a 302 to see if that works any better, but even if it does that is really a hack.
(Note that this is clearly a different issue than Android WebView, how to handle redirects in app instead of opening a browser -- as I already have a webview and am trying to intercept and manipulate redirection requests.)