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

Commit 15ca9241 authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #1747 from k9mail/xoauth2Backend

Back-end changes for Google XOAUTH2
parents 29dc3dd0 f9ed3047
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ buildscript {
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'
        classpath 'com.android.tools.build:gradle:2.2.2'
    }
}

+7 −0
Original line number Diff line number Diff line
@@ -16,6 +16,13 @@ public enum AuthType {
    CRAM_MD5,
    EXTERNAL,

    /**
     * XOAUTH2 is an OAuth2.0 protocol designed/used by GMail.
     *
     * https://developers.google.com/gmail/xoauth2_protocol#the_sasl_xoauth2_mechanism
     */
    XOAUTH2,

    /*
     * The following are obsolete authentication settings that were used with
     * SMTP. They are no longer presented to the user as options, but they may
+10 −0
Original line number Diff line number Diff line
package com.fsck.k9.mail;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;

import com.fsck.k9.mail.filter.Base64;
@@ -7,6 +8,7 @@ import com.fsck.k9.mail.filter.Hex;

public class Authentication {
    private static final String US_ASCII = "US-ASCII";
    private static final String XOAUTH_FORMAT = "user=%1s\001auth=Bearer %2s\001\001";

    /**
     * Computes the response for CRAM-MD5 authentication mechanism given the user credentials and
@@ -82,4 +84,12 @@ public class Authentication {
            throw new MessagingException("Something went wrong during CRAM-MD5 computation", e);
        }
    }

    public static String computeXoauth(String username, String authToken) throws UnsupportedEncodingException {
        String formattedAuthenticationString = String.format(XOAUTH_FORMAT, username, authToken);
        byte[] base64encodedAuthenticationString =
                Base64.encodeBase64(formattedAuthenticationString.getBytes());

        return new String(base64encodedAuthenticationString, US_ASCII);
    }
}
+5 −2
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ package com.fsck.k9.mail;

import android.content.Context;

import com.fsck.k9.mail.oauth.OAuth2TokenProvider;
import com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory;
import com.fsck.k9.mail.store.StoreConfig;
import com.fsck.k9.mail.ServerSettings.Type;
@@ -19,10 +20,12 @@ public abstract class Transport {
    // RFC 1047
    protected static final int SOCKET_READ_TIMEOUT = 300000;

    public synchronized static Transport getInstance(Context context, StoreConfig storeConfig) throws MessagingException {
    public static synchronized Transport getInstance(Context context, StoreConfig storeConfig) 
            throws MessagingException {
        String uri = storeConfig.getTransportUri();
        if (uri.startsWith("smtp")) {
            return new SmtpTransport(storeConfig, new DefaultTrustedSocketFactory(context));
            OAuth2TokenProvider oauth2TokenProvider = null;
            return new SmtpTransport(storeConfig, new DefaultTrustedSocketFactory(context), oauth2TokenProvider);
        } else if (uri.startsWith("webdav")) {
            return new WebDavTransport(storeConfig);
        } else {
+11 −0
Original line number Diff line number Diff line
package com.fsck.k9.mail.oauth;

public class AuthorizationException extends Exception {
    public AuthorizationException(String detailMessage, Throwable throwable) {
        super(detailMessage, throwable);
    }

    public AuthorizationException(String detailMessage) {
        super(detailMessage);
    }
}
Loading