[Vulcan/Hebe] Fix Firebase token for registration.

This commit is contained in:
Kuba Szczodrzyński 2021-02-20 21:31:52 +01:00
parent aef3f66654
commit ae20c30c88
2 changed files with 13 additions and 6 deletions

View File

@ -42,6 +42,7 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
method: Int = GET,
payload: JsonElement? = null,
baseUrl: Boolean = false,
firebaseToken: String? = null,
crossinline onSuccess: (json: T, response: Response?) -> Unit
) {
val url = "${if (baseUrl) data.apiUrl else data.fullApiUrl}$endpoint"
@ -66,7 +67,7 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
"AppVersion" to VULCAN_HEBE_APP_VERSION,
"CertificateId" to publicHash,
"Envelope" to payload,
"FirebaseToken" to data.app.config.sync.tokenVulcanHebe,
"FirebaseToken" to (firebaseToken ?: data.app.config.sync.tokenVulcanHebe),
"API" to 1,
"RequestId" to UUID.randomUUID().toString(),
"Timestamp" to timestampMillis,
@ -164,6 +165,7 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
endpoint: String,
query: Map<String, String> = mapOf(),
baseUrl: Boolean = false,
firebaseToken: String? = null,
crossinline onSuccess: (json: T, response: Response?) -> Unit
) {
val queryPath = query.map { it.key + "=" + URLEncoder.encode(it.value, "UTF-8") }.join("&")
@ -171,6 +173,7 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
tag,
if (query.isNotEmpty()) "$endpoint?$queryPath" else endpoint,
baseUrl = baseUrl,
firebaseToken = firebaseToken,
onSuccess = onSuccess
)
}
@ -180,6 +183,7 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
endpoint: String,
payload: JsonElement,
baseUrl: Boolean = false,
firebaseToken: String? = null,
crossinline onSuccess: (json: T, response: Response?) -> Unit
) {
apiRequest(
@ -188,6 +192,7 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
method = POST,
payload,
baseUrl = baseUrl,
firebaseToken = firebaseToken,
onSuccess = onSuccess
)
}

View File

@ -9,6 +9,7 @@ import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_REGISTER_NEW
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
import pl.szczodrzynski.edziennik.data.api.models.ApiError
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
import pl.szczodrzynski.edziennik.getString
import pl.szczodrzynski.edziennik.isNotNullNorEmpty
@ -63,7 +64,7 @@ class VulcanLoginHebe(val data: DataVulcan, val onSuccess: () -> Unit) {
}
private fun loginWithToken() {
//val szkolnyApi = SzkolnyApi(data.app)
val szkolnyApi = SzkolnyApi(data.app)
val hebe = VulcanHebe(data, null)
if (data.hebePublicKey == null || data.hebePrivateKey == null || data.hebePublicHash == null) {
@ -73,11 +74,11 @@ class VulcanLoginHebe(val data: DataVulcan, val onSuccess: () -> Unit) {
data.hebePublicHash = publicHash
}
/*szkolnyApi.runCatching({
data.app.config.sync.tokenVulcanHebe = getFirebaseToken("vulcan")
val firebaseToken = szkolnyApi.runCatching({
getFirebaseToken("vulcan")
}, onError = {
// screw errors
})*/
}) ?: data.app.config.sync.tokenVulcan
hebe.apiPost(
TAG,
@ -92,7 +93,8 @@ class VulcanLoginHebe(val data: DataVulcan, val onSuccess: () -> Unit) {
"SelfIdentifier" to data.buildDeviceId(),
"CertificateThumbprint" to data.hebePublicHash
),
baseUrl = true
baseUrl = true,
firebaseToken = firebaseToken
) { _: JsonObject, _ ->
data.apiToken = data.apiToken.toMutableMap().also {
it[data.symbol] = it[data.symbol]?.substring(0, 3)