nx: add login flow basics
parent
0a47baf16e
commit
56308aa8aa
|
@ -44,4 +44,5 @@ dependencies {
|
||||||
implementation "androidx.media3:media3-exoplayer:$mediaVersion"
|
implementation "androidx.media3:media3-exoplayer:$mediaVersion"
|
||||||
implementation "androidx.media3:media3-ui:$mediaVersion"
|
implementation "androidx.media3:media3-ui:$mediaVersion"
|
||||||
implementation "androidx.media3:media3-exoplayer-hls:$mediaVersion"
|
implementation "androidx.media3:media3-exoplayer-hls:$mediaVersion"
|
||||||
|
implementation "com.squareup.okhttp3:okhttp:4.10.0"
|
||||||
}
|
}
|
|
@ -90,7 +90,7 @@
|
||||||
|
|
||||||
// API is fine, redirect to login page
|
// API is fine, redirect to login page
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
window.nativex.login(data?.baseUrl || getMemoriesUrl().toString());
|
window.nativex.login(data.baseUrl, data.loginFlowUrl);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// CORS request, we know nothing about the server
|
// CORS request, we know nothing about the server
|
||||||
connError.innerText = `Failed to fetch server info.\nIs Memories installed and enabled?\n${urlStr}`;
|
connError.innerText = `Failed to fetch server info.\nIs Memories installed and enabled?\n${urlStr}`;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package gallery.memories
|
package gallery.memories
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.SoundEffectConstants
|
import android.view.SoundEffectConstants
|
||||||
|
@ -12,6 +13,11 @@ import gallery.memories.mapper.SystemImage
|
||||||
import gallery.memories.service.DownloadService
|
import gallery.memories.service.DownloadService
|
||||||
import gallery.memories.service.ImageService
|
import gallery.memories.service.ImageService
|
||||||
import gallery.memories.service.TimelineQuery
|
import gallery.memories.service.TimelineQuery
|
||||||
|
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.Request
|
||||||
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
|
import org.json.JSONObject
|
||||||
import java.io.ByteArrayInputStream
|
import java.io.ByteArrayInputStream
|
||||||
import java.net.URLDecoder
|
import java.net.URLDecoder
|
||||||
|
|
||||||
|
@ -90,11 +96,42 @@ import java.net.URLDecoder
|
||||||
get() = true
|
get() = true
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
fun login(server: String?) {
|
fun toast(message: String) {
|
||||||
if (server == null) return;
|
|
||||||
|
|
||||||
mActivity.runOnUiThread {
|
mActivity.runOnUiThread {
|
||||||
Toast.makeText(mActivity, server, Toast.LENGTH_LONG).show()
|
Toast.makeText(mActivity, message, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
fun login(baseUrl: String?, loginFlowUrl: String?) {
|
||||||
|
if (baseUrl == null || loginFlowUrl == null) return;
|
||||||
|
|
||||||
|
// Make POST request to login flow URL
|
||||||
|
val client = OkHttpClient()
|
||||||
|
val request = Request.Builder()
|
||||||
|
.url(loginFlowUrl)
|
||||||
|
.post("".toRequestBody("application/json".toMediaTypeOrNull()))
|
||||||
|
.build()
|
||||||
|
val response = client.newCall(request).execute()
|
||||||
|
|
||||||
|
// Read response body
|
||||||
|
val body = response.body?.string()
|
||||||
|
if (body == null) {
|
||||||
|
toast("Failed to get login flow response")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse response body as JSON
|
||||||
|
val json = JSONObject(body)
|
||||||
|
try {
|
||||||
|
val loginUrl = json.getString("login")
|
||||||
|
toast("Opening login page...")
|
||||||
|
|
||||||
|
// Open login page in browser
|
||||||
|
mActivity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(loginUrl)))
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "login: ", e)
|
||||||
|
toast("Failed to parse login flow response")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue