Closed JagadishaIncture closed 3 months ago
Hi @JagadishaIncture, I am not sure if I understood correctly. Do you want to inspect the current loading URL?
I Need to know is there any callback to show the override url or loading url?
You can inspect the state.lastLoadedUrl
similar to how you inspected loadingState
. However, it is recommended to use the snapshotflow
as shown in this sample.
I'm expecting some thing like
shouldOverrideUrlLoading
callback
Got you, we already discussed shouldOverrideUrlLoading
in this issue. Please subscribe to it for future updates.
When can We expect next release with this feature?
As I mentioned in my reply, we may not be able to support this feature in the short term due to some issues on all three platforms. You are welcome to implement it and submit a PR.
Hi @JagadishaIncture, I am not sure if I understood correctly. Do you want to inspect the current loading URL?
Yes... :)
Let me clarify since I am working on the same usecase: authenticating users with external authentication like Google or Keycloak by Open ID protocol.
In native or Flutter apps you normally do:
Since the WebView does not expose events, I tried by periodically checking the state.lastLoadedUrl
but it did not return the current webview url when that url was not loaded (since the passed callback url is actually a string targeting the app)
So, exposing a state.currentUrl
property (regardeless the successful loading or not), would allow to read it and complete the authentication flow.
Hi I'm working on supporting oAuth flow in 3 platforms.
here is the code base
`@Composable fun OAuth2WebView(utils: Utils,onAuthorizationCodeReceived: (String) -> Unit) {
val url="${OAuthConfig.AUTH_END_POINT}?response_type=code&client_id=${OAuthConfig.CLIENT_ID}&redirect_uri=${OAuthConfig.REDIRECT_URL}" val webViewState = rememberWebViewState(url) LogUtils.logDebug(StringResources.RESPONSE,url) Column(Modifier.fillMaxSize()) { val loadingState = webViewState.loadingState if (loadingState is LoadingState.Loading) { LinearProgressIndicator( progress = loadingState.progress, modifier = Modifier.fillMaxWidth() ) } WebView(webViewState, onDispose = { val currentUrl = webViewState.lastLoadedUrl LogUtils.logDebug(StringResources.RESPONSE,currentUrl.toString()) if (currentUrl?.startsWith(OAuthConfig.REDIRECT_URL) == true) { utils.getQueryParameter(currentUrl,"code")?.let { LogUtils.logDebug(StringResources.RESPONSE,it) onAuthorizationCodeReceived(it) } } }) }
}`
Problem is when auth success we are geting callback with reDirect url and auth code which we are not geting any control.
I tried onDispose which is working when i click back button but ideally not a good solution.. please give me workaround how to get the loading urls at runtime.
Hi, did you find any alternative?
@fabiobeoni Thanks for your explanation! I am working on supporting request interception in this PR. Would that resolve the problem?
Hi I'm working on supporting oAuth flow in 3 platforms. here is the code base `@Composable fun OAuth2WebView(utils: Utils,onAuthorizationCodeReceived: (String) -> Unit) {
val url="${OAuthConfig.AUTH_END_POINT}?response_type=code&client_id=${OAuthConfig.CLIENT_ID}&redirect_uri=${OAuthConfig.REDIRECT_URL}" val webViewState = rememberWebViewState(url) LogUtils.logDebug(StringResources.RESPONSE,url) Column(Modifier.fillMaxSize()) { val loadingState = webViewState.loadingState if (loadingState is LoadingState.Loading) { LinearProgressIndicator( progress = loadingState.progress, modifier = Modifier.fillMaxWidth() ) } WebView(webViewState, onDispose = { val currentUrl = webViewState.lastLoadedUrl LogUtils.logDebug(StringResources.RESPONSE,currentUrl.toString()) if (currentUrl?.startsWith(OAuthConfig.REDIRECT_URL) == true) { utils.getQueryParameter(currentUrl,"code")?.let { LogUtils.logDebug(StringResources.RESPONSE,it) onAuthorizationCodeReceived(it) } } }) }
}` Problem is when auth success we are geting callback with reDirect url and auth code which we are not geting any control. I tried onDispose which is working when i click back button but ideally not a good solution.. please give me workaround how to get the loading urls at runtime.
Hi, did you find any alternative?
Yes
` @Composable fun OAuth2WebView(platformUtils: PlatformUtils, localSharedStorage: LocalSharedStorage, onAuthorizationCodeReceived: (String) -> Unit) {
val url="${OAuthConfig.AUTH_END_POINT}?response_type=code&client_id=${OAuthConfig.CLIENT_ID}&redirect_uri=${OAuthConfig.REDIRECT_URL}"
val webViewState = rememberWebViewState(url)
LogUtils.logDebug(StringResources.RESPONSE,url)
Scaffold {
Column(Modifier.fillMaxSize()) {
val loadingState = webViewState.loadingState
if (loadingState is LoadingState.Loading) {
LinearProgressIndicator(progress = loadingState.progress, modifier = Modifier.fillMaxWidth())
webViewState.lastLoadedUrl?.let { currentUrl ->
LogUtils.logDebug(StringResources.RESPONSE, currentUrl)
if (currentUrl.startsWith(OAuthConfig.REDIRECT_URL)) {
platformUtils.getQueryParameter(currentUrl,"code")?.let {
LogUtils.logDebug(StringResources.RESPONSE,it)
localSharedStorage.saveAuthCode(it)
onAuthorizationCodeReceived(it)
}
}
}
}
WebView(webViewState)
}
}
} `
@fabiobeoni Thanks for your explanation! I am working on supporting request interception in this PR. Would that resolve the problem?
Yes it will.
` @composable fun OAuth2WebView(platformUtils: PlatformUtils, localSharedStorage: LocalSharedStorage, onAuthorizationCodeReceived: (String) -> Unit) {
val url="${OAuthConfig.AUTH_END_POINT}?response_type=code&client_id=${OAuthConfig.CLIENT_ID}&redirect_uri=${OAuthConfig.REDIRECT_URL}" val webViewState = rememberWebViewState(url) LogUtils.logDebug(StringResources.RESPONSE,url) Scaffold { Column(Modifier.fillMaxSize()) { val loadingState = webViewState.loadingState if (loadingState is LoadingState.Loading) { LinearProgressIndicator(progress = loadingState.progress, modifier = Modifier.fillMaxWidth()) webViewState.lastLoadedUrl?.let { currentUrl -> LogUtils.logDebug(StringResources.RESPONSE, currentUrl) if (currentUrl.startsWith(OAuthConfig.REDIRECT_URL)) { platformUtils.getQueryParameter(currentUrl,"code")?.let { LogUtils.logDebug(StringResources.RESPONSE,it) localSharedStorage.saveAuthCode(it) onAuthorizationCodeReceived(it) } } } } WebView(webViewState) } }
} `
Thanks for sharing
Hi I'm working on supporting oAuth flow in 3 platforms.
here is the code base
`@Composable fun OAuth2WebView(utils: Utils,onAuthorizationCodeReceived: (String) -> Unit) {
}`
Problem is when auth success we are geting callback with reDirect url and auth code which we are not geting any control.
I tried onDispose which is working when i click back button but ideally not a good solution.. please give me workaround how to get the loading urls at runtime.