Skip to content

Commit ea704e4

Browse files
committed
@
feat: add GitHub OAuth with PKCE and improve login UX - Add GitHub OAuth login with PKCE (client_id + client_secret) - Add loading dialog during OAuth token exchange - Hide logout button when not logged in - Swap button order: GitHub OAuth first (highlighted), Device Flow second - Add clear code_verifier after use to prevent duplicate requests - Fix handleOAuthCallback to skip if already logged in @
1 parent 4c11d1f commit ea704e4

5 files changed

Lines changed: 220 additions & 30 deletions

File tree

crates/hostsync-core/src/ffi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ mod android_jni {
311311
}
312312

313313
#[no_mangle]
314-
pub extern "system" fn Java_com_hostsync_app_MainActivity_hostsyncLogout(
314+
pub extern "system" fn Java_com_hostsync_app_MainActivity_hostsyncLogoutNative(
315315
_env: JNIEnv,
316316
_class: JClass,
317317
) -> jint {

crates/hostsync-core/src/storage.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ pub fn save_github_state(state: &GithubState) -> std::io::Result<()> {
118118
}
119119

120120
pub fn clear_github_state() -> std::io::Result<()> {
121-
let _ = std::fs::remove_file(token_path());
121+
let path = token_path();
122+
if path.exists() {
123+
std::fs::remove_file(&path)?;
124+
}
122125
Ok(())
123126
}
124127

mobile/android/app/src/main/AndroidManifest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
<action android:name="android.intent.action.MAIN" />
1919
<category android:name="android.intent.category.LAUNCHER" />
2020
</intent-filter>
21+
<!-- Handle OAuth callback: hostsync://oauth/callback?code=xxx -->
22+
<intent-filter>
23+
<action android:name="android.intent.action.VIEW" />
24+
<category android:name="android.intent.category.DEFAULT" />
25+
<category android:name="android.intent.category.BROWSABLE" />
26+
<data
27+
android:scheme="hostsync"
28+
android:host="oauth"
29+
android:pathPrefix="/callback" />
30+
</intent-filter>
2131
</activity>
2232

2333
<activity android:name=".TerminalActivity" />

mobile/android/app/src/main/java/com/hostsync/app/AppLanguage.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ data class AppStrings(
7777
val connectAnyway: String,
7878
val sync: String,
7979
val syncComplete: String,
80+
val githubAppClientId: String,
81+
val githubAppClientIdHint: String,
82+
val loginWithGithubApp: String,
83+
val loginWithBrowser: String,
84+
val deviceFlow: String,
85+
val loggingIn: String,
86+
val loggingInDesc: String,
8087
) {
8188
fun systemLanguageDetected(name: String): String {
8289
return when (language) {
@@ -188,6 +195,13 @@ object LanguagePrefs {
188195
connectAnyway = "Connect Anyway",
189196
sync = "Sync",
190197
syncComplete = "Sync complete",
198+
githubAppClientId = "GitHub App Client ID",
199+
githubAppClientIdHint = "Enter Client ID from your GitHub App",
200+
loginWithGithubApp = "Login with GitHub App",
201+
loginWithBrowser = "Login with Browser",
202+
deviceFlow = "Device Flow",
203+
loggingIn = "Logging in...",
204+
loggingInDesc = "Exchanging token with GitHub, please wait...",
191205
)
192206
AppLanguage.CHINESE -> AppStrings(
193207
language = AppLanguage.CHINESE,
@@ -242,6 +256,13 @@ object LanguagePrefs {
242256
connectAnyway = "仍然连接",
243257
sync = "同步",
244258
syncComplete = "同步完成",
259+
githubAppClientId = "GitHub App Client ID",
260+
githubAppClientIdHint = "输入你创建的 GitHub App 的 Client ID",
261+
loginWithGithubApp = "使用 GitHub App 登录",
262+
loginWithBrowser = "使用浏览器登录",
263+
deviceFlow = "Device Flow",
264+
loggingIn = "登录中...",
265+
loggingInDesc = "正在与 GitHub 交换 token,请稍候...",
245266
)
246267
}
247268
}

0 commit comments

Comments
 (0)