java - Dropbox 数据存储 API : Reliably determining if the user is authenticated

标签 java android authentication dropbox dropbox-api

问题

我正在使用 Dropbox Datastore API在我的应用程序中存储信息。我试图找出一种可靠的方法来检查用户是否通过 Dropbox 进行身份验证。


目前我正在使用这个辅助函数:

public boolean isLoggedIn(Context context){
    LogHelper logHelper = new LogHelper();
    DbxAccount dropboxAcount = getDropboxAccountManager(context).getLinkedAccount();

    if(dropboxAcount == null){
        return false;
    } else{
        if(dropboxAcount.isLinked() && dropboxAcount.getAccountInfo() != null){
            return true;
        } else{
            return false;
        }
    }
}



这样做的问题是,如果用户在登录后变得未经身份验证,例如,如果用户转到他们的保管箱设置并取消链接应用程序。发生这种情况时,上述功能将检测到用户已登录,只有当您尝试执行需要身份验证的操作(如写入数据存储)时,Dropbox api 才会意识到用户未通过身份验证。

问题

是否有可靠的方法来确定用户是否已通过 Dropbox Datastore API 进行身份验证?

最佳答案

来自 https://www.dropbox.com/developers/datastore/docs/android#com.dropbox.sync.android.DbxAccountManager.addListener :

void addListener(AccountListener l)

Adds an DbxAccountManager.AccountListener which will be called whenever a new account is linked or an existing account is unlinked. The listener will be called regardless of whether the account was unlinked using DbxAccount.unlink() or by the user on the Dropbox website.

这个通知仍然可能只在与服务器进行一些通信后才会触发,因为这是客户端知道应用程序外部发生的事情的唯一方式。

关于java - Dropbox 数据存储 API : Reliably determining if the user is authenticated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25510417/

相关文章:

android - 如何使用 FragmentPagerAdapter 在 fragment 之间滑动

windows - 如何将 WCF 中的服务访问限制为一组 Windows 帐户?

node.js - 检查客户端发送的 jwt 和参数是否相等是否太过分了?

java - 在 BlueJ 中打开网址

java - 从 Executor 创建 ExecutorService

Java Swing GridBagLayout : JLabel takes up too much space

android - 网络用户目录的设置gradle

java - 大量声明具有适当访问标识符的字段

android - 如何使用自定义 View 和选项卡创建 Android ActionBar

authentication - 将 Azure AD 身份验证与表单例份验证混合使用