[Api] Move FSLogin realms URL to GitHub sites.

This commit is contained in:
Kuba Szczodrzyński 2021-03-29 20:15:14 +02:00
parent 891be2f9dd
commit e6dec4c6c0
3 changed files with 18 additions and 11 deletions

View File

@ -367,8 +367,10 @@ class SzkolnyApi(val app: App) : CoroutineScope {
@Throws(Exception::class)
fun getRealms(registerName: String): List<LoginInfo.Platform> {
val response = api.fsLoginRealms(registerName).execute()
return parseResponse(response)
if (response.isSuccessful && response.body() != null) {
return response.body()!!
}
throw SzkolnyApiException(null)
}
@Throws(Exception::class)

View File

@ -39,6 +39,6 @@ interface SzkolnyService {
@GET("registerAvailability")
fun registerAvailability(): Call<ApiResponse<Map<String, RegisterAvailabilityStatus>>>
@GET("fsLogin/{registerName}")
fun fsLoginRealms(@Path("registerName") registerName: String): Call<ApiResponse<List<LoginInfo.Platform>>>
@GET("https://szkolny-eu.github.io/FSLogin/realms/{registerName}.json")
fun fsLoginRealms(@Path("registerName") registerName: String): Call<List<LoginInfo.Platform>>
}

View File

@ -12,25 +12,30 @@ import pl.szczodrzynski.edziennik.md5
class ApiCacheInterceptor(val app: App) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
if (Signing.appCertificate.md5() == app.config.apiInvalidCert) {
val request = chain.request()
if (request.url().host() == "api.szkolny.eu"
&& Signing.appCertificate.md5() == app.config.apiInvalidCert
) {
val response = ApiResponse<Unit>(
success = false,
errors = listOf(ApiResponse.Error("InvalidSignature", ""))
)
return Response.Builder()
.request(chain.request())
.request(request)
.protocol(Protocol.HTTP_1_1)
.code(401)
.message("Unauthorized")
.addHeader("Content-Type", "application/json")
.body(ResponseBody.create(
MediaType.parse("application/json"),
app.gson.toJson(response)
))
.body(
ResponseBody.create(
MediaType.parse("application/json"),
app.gson.toJson(response)
)
)
.build()
}
return chain.proceed(chain.request())
return chain.proceed(request)
}
}