mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-31 05:48:19 +01:00
[Vulcan/Hebe] Fix Firebase token for registration.
This commit is contained in:
parent
aef3f66654
commit
ae20c30c88
@ -42,6 +42,7 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
|||||||
method: Int = GET,
|
method: Int = GET,
|
||||||
payload: JsonElement? = null,
|
payload: JsonElement? = null,
|
||||||
baseUrl: Boolean = false,
|
baseUrl: Boolean = false,
|
||||||
|
firebaseToken: String? = null,
|
||||||
crossinline onSuccess: (json: T, response: Response?) -> Unit
|
crossinline onSuccess: (json: T, response: Response?) -> Unit
|
||||||
) {
|
) {
|
||||||
val url = "${if (baseUrl) data.apiUrl else data.fullApiUrl}$endpoint"
|
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,
|
"AppVersion" to VULCAN_HEBE_APP_VERSION,
|
||||||
"CertificateId" to publicHash,
|
"CertificateId" to publicHash,
|
||||||
"Envelope" to payload,
|
"Envelope" to payload,
|
||||||
"FirebaseToken" to data.app.config.sync.tokenVulcanHebe,
|
"FirebaseToken" to (firebaseToken ?: data.app.config.sync.tokenVulcanHebe),
|
||||||
"API" to 1,
|
"API" to 1,
|
||||||
"RequestId" to UUID.randomUUID().toString(),
|
"RequestId" to UUID.randomUUID().toString(),
|
||||||
"Timestamp" to timestampMillis,
|
"Timestamp" to timestampMillis,
|
||||||
@ -164,6 +165,7 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
|||||||
endpoint: String,
|
endpoint: String,
|
||||||
query: Map<String, String> = mapOf(),
|
query: Map<String, String> = mapOf(),
|
||||||
baseUrl: Boolean = false,
|
baseUrl: Boolean = false,
|
||||||
|
firebaseToken: String? = null,
|
||||||
crossinline onSuccess: (json: T, response: Response?) -> Unit
|
crossinline onSuccess: (json: T, response: Response?) -> Unit
|
||||||
) {
|
) {
|
||||||
val queryPath = query.map { it.key + "=" + URLEncoder.encode(it.value, "UTF-8") }.join("&")
|
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,
|
tag,
|
||||||
if (query.isNotEmpty()) "$endpoint?$queryPath" else endpoint,
|
if (query.isNotEmpty()) "$endpoint?$queryPath" else endpoint,
|
||||||
baseUrl = baseUrl,
|
baseUrl = baseUrl,
|
||||||
|
firebaseToken = firebaseToken,
|
||||||
onSuccess = onSuccess
|
onSuccess = onSuccess
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -180,6 +183,7 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
|||||||
endpoint: String,
|
endpoint: String,
|
||||||
payload: JsonElement,
|
payload: JsonElement,
|
||||||
baseUrl: Boolean = false,
|
baseUrl: Boolean = false,
|
||||||
|
firebaseToken: String? = null,
|
||||||
crossinline onSuccess: (json: T, response: Response?) -> Unit
|
crossinline onSuccess: (json: T, response: Response?) -> Unit
|
||||||
) {
|
) {
|
||||||
apiRequest(
|
apiRequest(
|
||||||
@ -188,6 +192,7 @@ open class VulcanHebe(open val data: DataVulcan, open val lastSync: Long?) {
|
|||||||
method = POST,
|
method = POST,
|
||||||
payload,
|
payload,
|
||||||
baseUrl = baseUrl,
|
baseUrl = baseUrl,
|
||||||
|
firebaseToken = firebaseToken,
|
||||||
onSuccess = onSuccess
|
onSuccess = onSuccess
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -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.DataVulcan
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
|
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
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.getString
|
||||||
import pl.szczodrzynski.edziennik.isNotNullNorEmpty
|
import pl.szczodrzynski.edziennik.isNotNullNorEmpty
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ class VulcanLoginHebe(val data: DataVulcan, val onSuccess: () -> Unit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun loginWithToken() {
|
private fun loginWithToken() {
|
||||||
//val szkolnyApi = SzkolnyApi(data.app)
|
val szkolnyApi = SzkolnyApi(data.app)
|
||||||
val hebe = VulcanHebe(data, null)
|
val hebe = VulcanHebe(data, null)
|
||||||
|
|
||||||
if (data.hebePublicKey == null || data.hebePrivateKey == null || data.hebePublicHash == 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
|
data.hebePublicHash = publicHash
|
||||||
}
|
}
|
||||||
|
|
||||||
/*szkolnyApi.runCatching({
|
val firebaseToken = szkolnyApi.runCatching({
|
||||||
data.app.config.sync.tokenVulcanHebe = getFirebaseToken("vulcan")
|
getFirebaseToken("vulcan")
|
||||||
}, onError = {
|
}, onError = {
|
||||||
// screw errors
|
// screw errors
|
||||||
})*/
|
}) ?: data.app.config.sync.tokenVulcan
|
||||||
|
|
||||||
hebe.apiPost(
|
hebe.apiPost(
|
||||||
TAG,
|
TAG,
|
||||||
@ -92,7 +93,8 @@ class VulcanLoginHebe(val data: DataVulcan, val onSuccess: () -> Unit) {
|
|||||||
"SelfIdentifier" to data.buildDeviceId(),
|
"SelfIdentifier" to data.buildDeviceId(),
|
||||||
"CertificateThumbprint" to data.hebePublicHash
|
"CertificateThumbprint" to data.hebePublicHash
|
||||||
),
|
),
|
||||||
baseUrl = true
|
baseUrl = true,
|
||||||
|
firebaseToken = firebaseToken
|
||||||
) { _: JsonObject, _ ->
|
) { _: JsonObject, _ ->
|
||||||
data.apiToken = data.apiToken.toMutableMap().also {
|
data.apiToken = data.apiToken.toMutableMap().also {
|
||||||
it[data.symbol] = it[data.symbol]?.substring(0, 3)
|
it[data.symbol] = it[data.symbol]?.substring(0, 3)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user