Accessing web with HTTP auth #167
-
|
Hi, I'm trying to create Android app for the first time. I'm struggling with using it with web that is behind HTTPAuth (test server). I tried creating custom WebView, as described here, and calling setHttpAuthUsernamePassword (which is deprecated, but I just wanted to make first working version). I would appreciate any help for that. Thanks for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
|
In my code I see something like this I think this does the magic. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks to @MichalSznajder, code of demo application and the Hotwire native for Rails developers book , I managed to create a working code:
package com.myaap
import android.app.Application
import dev.hotwire.core.config.Hotwire
import dev.hotwire.navigation.config.defaultFragmentDestination
import dev.hotwire.navigation.config.registerFragmentDestinations
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
configureApp()
}
private fun configureApp(){
// CustomWebFragment manages HTTPAuth connection to sandbox
Hotwire.defaultFragmentDestination = CustomWebFragment::class
Hotwire.registerFragmentDestinations(CustomWebFragment::class)
}
}
<application
android:name=".MyApplication"
...
package com.myapp
import android.webkit.HttpAuthHandler
import dev.hotwire.navigation.destinations.HotwireDestinationDeepLink
import dev.hotwire.navigation.fragments.HotwireWebFragment
@HotwireDestinationDeepLink(uri = "hotwire://fragment/web")
open class CustomWebFragment : HotwireWebFragment() {
override fun onReceivedHttpAuthRequest(handler: HttpAuthHandler, host: String, realm: String) {
handler.proceed("ourusername", "oursecretpasswork")
}
}And now I am sucessfully getting through HTTPAuth. It's advisable not to have username and password hardcoded, but I don't know yet how to do that. |
Beta Was this translation helpful? Give feedback.
-
|
@MichalSznajder didn't you by chance also did solve this for iOS? 😁 |
Beta Was this translation helpful? Give feedback.
Thanks to @MichalSznajder, code of demo application and the Hotwire native for Rails developers book , I managed to create a working code: