cianru / huawei-appgallery-publish-gradle-plugin

Huawei AppGallery Publish Gradle Plugin allows you to publish the android release build file (*.apk or *.aab) to the Huawei AppGallery store
Apache License 2.0
111 stars 20 forks source link

Error Get App ID #11

Closed ipBill closed 3 years ago

ipBill commented 3 years ago
Screen Shot 2563-11-06 at 12 33 26
cosic commented 3 years ago

@ipBill Hi! What version of Android Gradle Plugin are you using? Could you get me a little bit more information about you environment?

mdenissov commented 3 years ago

@ipBill Looks, like you uses wrong client_id & client_secret. Verify, that you create API Access via https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agcapi-getstarted

Plugin returns null as token value and getAppID doesn't work when uses wrong client_id & client_secret.

Reqeust:

https://connect-api.cloud.huawei.com/api/oauth2/v1/token

{"client_id":"**wrong**","client_secret":"**wrong**","grant_type":"client_credentials"}

Answer:

**STATUS CODE: 200 OK**
{
    "ret": {
        "code": 203882498,
        "msg": "[AppGalleryConnectApiPermissionService]invalid client id"
    },
    "products": [],
    "permissions": []
}

Plugin deserializes the answer into AccessTokenResponse:

import com.google.gson.annotations.SerializedName

internal data class AccessTokenResponse(
    @SerializedName("access_token")
    val accessToken: String,
    @SerializedName("expires_in")
    val expiresIn: Long
)

HttpClientHelper.kt


if (statusCode == HttpStatus.SC_OK) {
   //***
   val result = gson.fromJson(rawResult, clazz)
   //***
}

But the GSON setups NULLs for all AccessTokenResponse's fields. See: https://stackoverflow.com/questions/52837665/why-kotlin-data-classes-can-have-nulls-in-non-nullable-fields-with-gson

HuaweiPublishTask.kt

        Logger.i("Get Access Token")
        val token = huaweiService.getToken(        // <-- token is NULL
            clientId = config.credentials.clientId,
            clientSecret = config.credentials.clientSecret
        )

        Logger.i("Get App ID")
        val appInfo = huaweiService.getAppID(
            clientId = config.credentials.clientId,

            token = token,      // <-- token is NULL

            packageName = variant.applicationId
        )

Be attention! DO NOT SET UP a project in the project field, use N/A, otherwise you will get 403 client token authorization fail. error.

ipBill commented 3 years ago

Thank you for your suggestion. It's my fault. I'm so sorry.