Skip to content

Commit

Permalink
fix(Auth): NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
JellyBrick committed Apr 28, 2022
1 parent d56fe45 commit 0d119c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
25 changes: 11 additions & 14 deletions src/main/kotlin/be/zvz/kotlininside/security/Auth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -210,24 +210,21 @@ class Auth {
* @param hashedAppKey SHA256 단방향 암호화된 value_token 값입니다.
* @return [java.lang.String] app_id를 반환합니다.
*/
@Throws(HttpException::class)
fun fetchAppId(hashedAppKey: String): String {
fcmToken = fetchFcmToken()

val appId = try {
val option = Request.getDefaultOption()
.addMultipartParameter("value_token", hashedAppKey)
.addMultipartParameter("signature", Const.DC_APP_SIGNATURE)
.addMultipartParameter("pkg", Const.DC_APP_PACKAGE)
.addMultipartParameter("vCode", Const.DC_APP_VERSION_CODE)
.addMultipartParameter("vName", Const.DC_APP_VERSION_NAME)
.addMultipartParameter("client_token", fcmToken)
val option = Request.getDefaultOption()
.addMultipartParameter("value_token", hashedAppKey)
.addMultipartParameter("signature", Const.DC_APP_SIGNATURE)
.addMultipartParameter("pkg", Const.DC_APP_PACKAGE)
.addMultipartParameter("vCode", Const.DC_APP_VERSION_CODE)
.addMultipartParameter("vName", Const.DC_APP_VERSION_NAME)
.addMultipartParameter("client_token", fcmToken)

JsonBrowser.parse(KotlinInside.getInstance().httpInterface.upload(ApiUrl.Auth.APP_ID, option))
} catch (e: HttpException) {
return ""
}
val appId = JsonBrowser.parse(KotlinInside.getInstance().httpInterface.upload(ApiUrl.Auth.APP_ID, option))

return appId.index(0).get("app_id").text()!!
return appId.get("app_id").text() ?: throw HttpException(RuntimeException("Can't get app_id: ${appId.text()}"))
}

/**
Expand All @@ -251,7 +248,7 @@ class Auth {
ApiUrl.Auth.LOGIN,
option
)
).index(0)
)

val detail = SessionDetail(
result = json.get("result").asBoolean(),
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/be/zvz/kotlininside/KotlinInsideTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class KotlinInsideTest {
fun initKotlinInside() {
KotlinInside.createInstance(
Anonymous("ㅇㅇ", "1234"),
DefaultHttpClient(true, true)
DefaultHttpClient()
)
}

Expand Down

0 comments on commit 0d119c5

Please sign in to comment.