安卓應用開發中Login,Maintaining Login,Logout的最佳實踐是怎樣?

兩個問題:

1. 請大神分析一下QQ,微信,支付寶等BAT上億用戶客戶端,關於"登錄","登錄狀態保持"以及"註銷登錄"的實現方式。

2. 結合安全性,以及用戶友好性,介紹一下您個人的最佳實踐。


用 Android 內置的官方標準方法,包括 Authenticator, AccountManager:

http://developer.android.com/reference/android/accounts/AbstractAccountAuthenticator.html

http://developer.android.com/reference/android/accounts/AccountManager.html

有以下幾個特點:

* 標準的授權流程,簡化了開發授權的過程;

* 為你處理拒絕訪問的情況;

* 可以處理同一賬戶的多種 token 類型(如只讀,完全控制等);

* 可以在多個應用間共享 token, 支持 SyncAdapter 等 Background Processes;

* token 等關鍵內容和一些附加賬戶信息會直接存放在系統的賬戶資料庫,交由系統管理;

* 既可以在應用內管理,也可以在系統 設置 -&> 賬戶 中管理。

最典型的例子就是 Google 賬戶了,整個手機的所有 Google 應用可以通過同一個賬戶訪問不同的數據。

需要實現三個部分:

1. Authenticators, 具體的登錄流程的處理;

2. Activities, 用來顯示登錄等等界面;

3. Service, 用於和 Authenticator 通信。

Android Developers 上有相關的 Tutorial, 另外還有一篇比較詳細的實現教程:

Blog: Write your own Android Authenticator

Github Repo: Udinic/AccountAuthenticator · GitHub

流程(圖片來自 http://blog.udinic.com/2013/04/24/write-your-own-android-authenticator/):

設置 -&> 賬戶 中的效果:


謝邀。我當時寫賬號模塊時主要是參考了以下文章:

1.Android developer上的:http://developer.android.com/training/sync-adapters/creating-authenticator.html 裡面有詳細的介紹和sample;

下面是一個典型的Authenticator實現。

/*
* Implement AbstractAccountAuthenticator and stub out all
* of its methods
*/
public class Authenticator extends AbstractAccountAuthenticator {
// Simple constructor
public Authenticator(Context context) {
super(context);
}
// Editing properties is not supported
@Override
public Bundle editProperties(
AccountAuthenticatorResponse r, String s) {
throw new UnsupportedOperationException();
}
// Don"t add additional accounts
@Override
public Bundle addAccount(
AccountAuthenticatorResponse r,
String s,
String s2,
String[] strings,
Bundle bundle) throws NetworkErrorException {
return null;
}
// Ignore attempts to confirm credentials
@Override
public Bundle confirmCredentials(
AccountAuthenticatorResponse r,
Account account,
Bundle bundle) throws NetworkErrorException {
return null;
}
// Getting an authentication token is not supported
@Override
public Bundle getAuthToken(
AccountAuthenticatorResponse r,
Account account,
String s,
Bundle bundle) throws NetworkErrorException {
throw new UnsupportedOperationException();
}
// Getting a label for the auth token is not supported
@Override
public String getAuthTokenLabel(String s) {
throw new UnsupportedOperationException();
}
// Updating user credentials is not supported
@Override
public Bundle updateCredentials(
AccountAuthenticatorResponse r,
Account account,
String s, Bundle bundle) throws NetworkErrorException {
throw new UnsupportedOperationException();
}
// Checking features for the account is not supported
@Override
public Bundle hasFeatures(
AccountAuthenticatorResponse r,
Account account, String[] strings) throws NetworkErrorException {
throw new UnsupportedOperationException();
}
}

考慮到有的童鞋可能fq不方便,我把developer中關於Authenticator的部分放到我的blog中了,可以在Creating a Stub Authenticator中訪問。另外王龍海的個人博客 中有關於ImageLoader,圖片處理等的分析,有興趣的童鞋可以看下。

2.Udinic大神關於Authenticator的兩篇文章,結合示例寫的,但是我記得blog裡面是有些細節問題的,完全照著做是不行的。後面如果有問題的話再私信我,我把我的代碼模塊給你。

1)Write your own Android Authenticator

2)Write your own Android Sync Adapter

前一篇是關於構建Authenticator的,後一篇是關於賬號更新的。

===============歪樓的分割線=========================

上面介紹了在Android中構建Authenticator的方法,但是其實在大公司是有賬號sdk調用的,賬號註冊,登錄,保持,找回密碼等都在裡面,我更傾向於賬號團隊是用C/C++代碼寫好核心功能,然後針對不同客戶端進行封裝,不然維護就是個噩夢。

附上我的github:HiWong (HiWong) · GitHub,裡面有很多Android開發中常用的component,請隨意fork,記得給小星星哈。


1.採用服務端下發token的方式,有超時時間

2.本地保存token,自動登錄並拉取新token

3.超時未拉取新token重新登錄

4.多應用間可以共享此token

安全方面如果自身沒有很強的安全實力就做做樣子就行,一旦涉及敏感介面,必須驗證手機就ok


謝 @王快看看邀。

作為半個小白,僅就自己曾經做過的一個項目說一下:

登錄:將用戶輸入的用戶名和密碼提交給伺服器進行驗證(使用第三方登錄則使用Token);

保持登錄狀態:跟登錄的實現一樣,只是用戶不需要手動登錄而已;(或者題主的意思是退出程序之後仍然接收消息推送?)

註銷:下次進入程序需要重新登錄,另外需要註銷該用戶在該手機上的消息推送;

安全性:每次讓用戶輸入密碼比較安全;

用戶友好性:用戶只需要輸入一次密碼比較友好;

最佳實踐:客戶/產品經理開心就好喏!

(不知道有沒有曲解題主的意思)


等大神回答。我只是把token還有昵稱等信息用shareperence加base64編碼保存起來,伺服器返回token無效的會提示重新登錄,感覺沒什麼安全性可言。。


推薦閱讀:

產品經理如何做電話訪談?怎麼整理結果?
如何正確的理解和分析用戶需求?
如果要從事項目經理/產品經理這條職業道路,需求的技能是哪些?存在什麼先後順序嗎?或者說如何開始?

TAG:產品經理 | Android開發 | Android | Android開發諮詢 |