နားလည်ထားရမယ့် အချက်
Mobile authentication ရဲ့ core flow: user login -> app က credential ကို auth server ဆီပို့ -> server က token ပြန်ဖြေ -> app က token ကို secure storage ထဲ သိမ်းပြီး API request တွေနဲ့ ချိတ်ဆက်သည်။
- Access Token — short-lived, API request တစ်ခုစီနှင့် ပို့သည်
- Refresh Token — ကြာရှည်ခံပြီး access token အသစ်ရဖို့ full re-login မလိုဘဲ သုံးသည်
- Session Token — server က တိုက်ရိုက် track လုပ်သော active session
- JWT သည် common ဖြစ်သော်လည်း token format တစ်ခုတည်း universal မဟုတ်ပါ
OAuth/social login ဟာ delegated flow ထပ်ထည့်သည် — app က provider ဆီ redirect, user က ဒီနေရာမှာ approve, app/backend က authorized session ပြန်ရသည်; handoff ဟာ deep link မှတစ်ဆင့် ပြန်ရောက်ပြီး ကိုယ်ပိုင် security consideration ရှိသည်။
Biometric Unlock သည် Backend Authentication ကို အစားထိုးမည်မဟုတ်ပါ
Biometric unlock ဟာ local app access ကို ကာကွယ်ပေးသည့် factor တစ်ခုသာဖြစ်ပြီး backend authentication ကို အစားထိုးမည် မဟုတ်ပါ။ Face ID (သို့) fingerprint ဟာ device ကိုင်ဆောင်သူ ဘယ်သူလဲဆိုတာကို ကိုယ်ဟန်ပြသာ အတည်ပြုပေးပြီး API တစ်ခုက အားထားနေတဲ့ server-side token ကို ၎င်းကိုယ်တိုင် issue (သို့) validate မလုပ်ပေးပါ။
- Access Token
- API request တစ်ခုစီနှင့်အတူ ပို့ဆောင်ရသည့် short-lived token — authenticated request ကို server ဘက်က အသိအမှတ်ပြုစေသည်။
- Refresh Token
- access token expire ဖြစ်ပြီးနောက် full re-login မလိုဘဲ access token အသစ်တစ်ခု ရယူဖို့ သုံးသည့် ပိုကြာရှည်ခံသော token။
MOBILE AUTHENTICATION ARCHITECTURE
----------------------------------
MOBILE AUTHENTICATION ARCHITECTURE
-----
Mobile App --login--> Auth Server
|
v
Session / Access Token
|
v
Secure Local Storage
|
v
Authenticated API Requests
OAuth / social login branch:
Mobile App --redirect--> Provider (Apple/Google)
|
User Approves
|
v
App/Backend gets Authorized Sessionလက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Mobile authentication ရဲ့ ခက်ခဲဆုံးအပိုင်းဟာ initial login မဟုတ်ဘဲ session ကို ပြီးနောက် မှန်ကန်စွာ ဆက်လက် ထိန်းထားနိုင်ရေးပါ — request တစ်ခုစီမတိုင်ခင် token state ကို စစ်ဆေးရပါတယ်။
- Expiration မစစ်ဆေးရင် ပျက်စီးမှာသေချာတဲ့ request တွေကို တိတ်တဆိတ်ပို့ပြီး error ရှုပ်ထွေးစေသည်
- ကြိုတင် refresh အလွန်အကျွံလုပ်ရင် auth server ဆီ call တွေ အကျိုးမရှိဘဲ ဖြုန်းတီးသည်
- Expired refresh token ကို detect မလုပ်ရင် user ကို failing request loop ထဲ ညှပ်ထားနိုင်သည်
OAuth callback တွေဟာ deep link ကနေ control ပြန်ရောက်လာတဲ့အတွက် app က authorization ကို ၎င်းလုပ်ခဲ့တဲ့ request နဲ့ ကိုက်ညီမကိုက်ညီ validate လုပ်ရပါတယ်။
Biometric Unlock သည် Backend Authentication ကို အစားထိုးမည်မဟုတ်ပါ
Face ID (သို့) fingerprint ဟာ local device/app access ကို ကာကွယ်ပေးတာသာဖြစ်ပြီး၊ API request တစ်ခုက အားထားနေတဲ့ server-side access/refresh token ကို ၎င်းကိုယ်တိုင် issue (သို့) validate မလုပ်ပေးပါ — full mobile authentication architecture ရဲ့ အစားထိုးမဟုတ်ပါ။
အတူတူ စမ်းရေးကြည့်မယ်
function decideAuthAction(session, now) {
const { accessTokenExpiresAt, refreshTokenExpiresAt } = session;
if (now < accessTokenExpiresAt) {
return "proceed with current access token";
}
if (now < refreshTokenExpiresAt) {
return "refresh access token, then proceed";
}
return "require full re-login (refresh token also expired)";
}
const nowTs = 1000000;
const validSession = { accessTokenExpiresAt: nowTs + 100000, refreshTokenExpiresAt: nowTs + 500000 };
const expiredAccessValidRefresh = { accessTokenExpiresAt: nowTs - 1000, refreshTokenExpiresAt: nowTs + 500000 };
const bothExpired = { accessTokenExpiresAt: nowTs - 1000, refreshTokenExpiresAt: nowTs - 500 };
console.log("Valid session:", decideAuthAction(validSession, nowTs));
console.log("Expired access, valid refresh:", decideAuthAction(expiredAccessValidRefresh, nowTs));
console.log("Both tokens expired:", decideAuthAction(bothExpired, nowTs));Valid session: proceed with current access token
Expired access, valid refresh: refresh access token, then proceed
Both tokens expired: require full re-login (refresh token also expired)
Access token ဆက်တရားဝင်နေရင် ချက်ချင်းဆက်သွားပြီး၊ access token expire ဖြစ်သော်လည်း refresh token ကောင်းနေရင် refresh အရင်လုပ်ကာ၊ နှစ်ခုစလုံး expire ဖြစ်မှသာ full re-login လိုအပ်ကြောင်း တွေ့ရသည်။၅ မိနစ် စမ်းကြည့်
session object ထဲ တတိယ field `isRevoked` ကို ထပ်ထည့်ပြီး `decideAuthAction` ကို update လုပ်ပါ — token ဟာ technically expire မဖြစ်သေးရင်တောင် revoked ဖြစ်နေရင် full re-login ကို အမြဲ force လုပ်စေရမည်; valid-looking ဒါပေမယ့် revoked ဖြစ်နေတဲ့ token တစ်ခုနဲ့ စမ်းသပ်ပါ။
သတိလေးတစ်ချက်
JWT ကို token format တစ်ခုတည်းသာ ရှိသလို ယူဆပြီး session/refresh token concept ကွဲပြားကြောင်း လျစ်လျူရှုခြင်း
Biometric unlock ကို backend authentication ရဲ့ အစားထိုးအဖြစ် ထင်မှတ်ပြီး server-side token validation ကို လုံးဝ မလုပ်ခြင်း
OAuth — Wikipedia — How Mobile Apps Work