【问题标题】:Several issues with Ktor server authentication in AndroidAndroid 中 Ktor 服务器身份验证的几个问题
【发布时间】:2021-06-22 18:12:35
【问题描述】:

在 minSdkVersion 25 上使用 io.ktor:ktor-auth:1.5.2 时,在尝试构建项目并添加 implementation 'com.google.guava:guava:27.0.1-android' 后,我得到“无法访问类 'com.google.common.util.concurrent.ListenableFuture'”到build.gradle 它又工作了,就像建议的here 一样。

但是,当我尝试生成 JWT 令牌时,JWTCreator.Builder.sign() 方法使用来自 org.apache.commons.codec.binary.Base64 的 Base64.encodeBase64URLSafeString(),我收到以下错误:

java.lang.NoSuchMethodError: No static method encodeBase64URLSafeString([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar)

除了手动覆盖整个 Ktor 类(这甚至不可能)之外,我还能做些什么吗?请注意,我已经添加了implementation 'commons-codec:commons-codec:1.15',但没有任何改变。

【问题讨论】:

    标签: android kotlin ktor


    【解决方案1】:

    在 Android 上使用 JWTDecode.Android(即使是 Kotlin):

    implementation "com.auth0.android:jwtdecode:2.0.0"
    

    【讨论】:

    • 没有任何变化,因为使用 org.apache.commons.codec.binary.Base64 的代码在 Ktor 内部。
    猜你喜欢
    • 2013-07-30
    • 1970-01-01
    • 2016-01-02
    • 2019-11-17
    • 2021-12-11
    • 1970-01-01
    • 2012-02-28
    • 2012-06-16
    • 1970-01-01
    相关资源
    最近更新 更多