OneDrive / onedrive-sdk-android

OneDrive SDK for Android!
https://dev.onedrive.com
Other
148 stars 52 forks source link

Just try to login silent, without Login Dialog poping up if it didn't work? #47

Closed ThomasSHA closed 8 years ago

ThomasSHA commented 8 years ago

What I want to achieve: When my App is opened I want to try a silent login. If that works, I can update stuff like free space etc.. BUT If it doesn't work, I want the SDK to do nothing (until the user explicitly wants to connect to onedrive).

Till now I haven't found a nice solution. loginAndBuildClient pops up the Login Dialog if silent login fails.

What I did till now: I've overwritten the OneDriveClientand basically copied the loginAndBuildClient but instead of calling login when loginSilent fails I return the AccountInfo (which is null in that case).

This works for now. But maybe you got another little trick for me ;)

peternied commented 8 years ago

I would suggest that you create a new IAuthenticator that returns null when login(...) is called, instead of prompting the user for and UI.

Here is an example that should work for MSA accounts, and modifying ADAL or the Disambiguation authenticators should follow a similar path.

final MSAAuthenticator silentOnlyMsaAuthenticator = new MSAAuthenticator() {
    @Override
    public String getClientId() {
        return "000000000000000";
    }

    @Override
    public String[] getScopes() {
        return new String[] {"onedrive.appfolder", "wl.offline_access"};
    }

    @Override
    public synchronized IAccountInfo login(String emailAddressHint) throws ClientException {
        return null;
    }
};
ThomasSHA commented 8 years ago

thx. this works too :)