https://kotlinlang.org logo
#ktor
Title
# ktor
s

Simon Schubert

05/22/2019, 5:29 PM
Is the ktor client auth feature not multiplatform compatible? i thought so but getting unresolved reference and https://github.com/ktorio/ktor/tree/master/ktor-features/ktor-auth only has a jvm folder
c

cy

05/22/2019, 5:29 PM
server features are not mpp yet
client features are placed in another place
Do you have client auth dependencies included?
s

Simon Schubert

05/22/2019, 5:31 PM
c

cy

05/22/2019, 5:31 PM
It is mpp
s

Simon Schubert

05/22/2019, 5:32 PM
in my common dependencies i have implementation "io.ktorktor client auth$ktor_version"
along with implementation "io.ktorktor client core$ktor_version"
ktor_version = "1.2.0"
in my android dependencies implementation "io.ktorktor client android$ktor_version"
c

cy

05/22/2019, 5:39 PM
Just tried it and it seems to work well
Copy code
commonMain {
    dependencies {
        implementation kotlin('stdlib-common')
        implementation "io.ktor:ktor-client-core:1.2.0"
        implementation "io.ktor:ktor-client-auth:1.2.0"
    }
}
Do you see any errors? What is your gradle version?
We actually have known issue regarding gradle metadata version: we use gradle 5.3 in ktor that is too new. Perhaps you need to upgrade it
s

Simon Schubert

05/22/2019, 5:45 PM
thanks, great that it is mpp compatible. i wasn't sure for a second. my gradle is 5.4.1. the in my common code it doesn't show an error. import io.ktor.client.features.auth.Auth is resolving. but when i try to compile it, it doesn't resolve
wait I will try to use gradle 5.3
c

cy

05/22/2019, 5:50 PM
If no luck you can always include jvm dependcies explicitly
Copy code
jvmMain {
    dependencies {
        implementation kotlin('stdlib')
        implementation "io.ktor:ktor-client-core-jvm:1.2.0"
        implementation "io.ktor:ktor-client-auth-jvm:1.2.0"
    }
}
maybe there is something obviously wrong
meanwhile I will try the approach you suggested
damn I couldn't get it working. any ideas what I'm doing wrong? I will give it another try tomorrow
I had simliar problems trying to add the kotlin kissme library to the project. So I came to the conclusion that it has nothing to do with ktor itself. There might be something wrong with my gradle setup. Sorry for the false alarm and thank you for helping out! 🙂
Adding
Copy code
implementation "io.ktor:ktor-client-auth-jvm:$ktor_version"
to the android dependencies finally lets me compile the android project. But somehow it doesn't add a
Copy code
Authorization
header to the request. I double checked everything and checking the reuest with charles but no header gets throught.
Copy code
HttpClient {
                    install(Auth) {
                        basic {
                            username = email
                            password = pw
                        }
                    }
                }
Are there any nown issues about that behavoir?
4 Views