Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2bc248e1 authored by daquexian's avatar daquexian
Browse files

implement OAuth 2.0 without Android account system

parent c21f6a56
Loading
Loading
Loading
Loading
+1 −30
Original line number Diff line number Diff line
@@ -3,8 +3,6 @@ package com.fsck.k9.mail.oauth;

import java.util.List;

import android.app.Activity;

import com.fsck.k9.mail.AuthenticationFailedException;
import com.fsck.k9.mail.OAuth2NeedUserPromptException;

@@ -16,34 +14,7 @@ public interface OAuth2TokenProvider {
    int OAUTH2_TIMEOUT = 30000;

    
    /**
     * @return Accounts suitable for OAuth 2.0 token provision.
     */
    List<String> getAccounts();

    /**
     * Provides an asynchronous response to an
     * {@link OAuth2TokenProvider#authorizeAPI(String, Activity, OAuth2TokenProviderAuthCallback)} request
     */
    interface OAuth2TokenProviderAuthCallback {

        void success();

        void failure(AuthorizationException e);
    }

    /**
     * Request API authorization. This is a foreground action that may produce a dialog to interact with.
     *
     * @param username
     *         Username
     * @param activity
     *         The responsible activity
     * @param callback
     *         A callback to process the asynchronous response
     */
    void authorizeAPI(String username, Activity activity,
                        OAuth2TokenProviderAuthCallback callback);
    boolean exchangeCode(String username, String code);

    /**
     * Fetch a token. No guarantees are provided for validity.
+1 −5
Original line number Diff line number Diff line
@@ -1037,14 +1037,10 @@ public class ImapConnectionTest {
            }

            @Override
            public List<String> getAccounts() {
            public boolean exchangeCode(String username, String code) {
                throw new UnsupportedOperationException();
            }

            @Override
            public void authorizeAPI(String username, Activity activity, OAuth2TokenProviderAuthCallback callback) {
                throw new UnsupportedOperationException();
            }
        };
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ dependencies {
    compile "com.jakewharton.timber:timber:${timberVersion}"
    compile 'net.jcip:jcip-annotations:1.0'

    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'

    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
+5 −1
Original line number Diff line number Diff line
@@ -16,10 +16,12 @@ import java.util.concurrent.ConcurrentHashMap;

import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;

import com.fsck.k9.account.GmailOAuth2TokenStore;
import com.fsck.k9.activity.AccountConfig;
import com.fsck.k9.activity.setup.CheckDirection;
import com.fsck.k9.helper.EmailHelper;
@@ -29,7 +31,6 @@ import com.fsck.k9.mail.ServerSettings;
import com.fsck.k9.mail.Transport;
import timber.log.Timber;

import com.fsck.k9.account.AndroidAccountOAuth2TokenStore;
import com.fsck.k9.helper.Utility;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.MessagingException;
@@ -610,6 +611,9 @@ public class Account implements BaseAccount, AccountConfig {
        // TODO: Remove preference settings that may exist for individual
        // folders in the account.
        editor.commit();

        SharedPreferences oauth2SP = ((GmailOAuth2TokenStore) Globals.getOAuth2TokenProvider()).getSharedPreference();
        oauth2SP.edit().remove(getEmail()).apply();
    }

    private static int findNewAccountNumber(List<Integer> accountNumbers) {
+2 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.support.annotation.StringRes;

import com.fsck.k9.Account.SortType;
import com.fsck.k9.account.AndroidAccountOAuth2TokenStore;
import com.fsck.k9.account.GmailOAuth2TokenStore;
import com.fsck.k9.activity.MessageCompose;
import com.fsck.k9.activity.UpgradeDatabases;
import com.fsck.k9.controller.MessagingController;
@@ -539,7 +540,7 @@ public class K9 extends Application {
        super.onCreate();
        app = this;
        Globals.setContext(this);
        Globals.setOAuth2TokenProvider(new AndroidAccountOAuth2TokenStore(this));
        Globals.setOAuth2TokenProvider(new GmailOAuth2TokenStore(this));

        K9MailLib.setDebugStatus(new K9MailLib.DebugStatus() {
            @Override public boolean enabled() {
Loading