// Path: app/src/main/java/com/microsoft/o365_android_onenote_rest/conf/ServiceConstants.java
// public class ServiceConstants {
// 
//     // MSA
//     public static final String MSA_CLIENT_ID = "<Your MSA CLIENT ID>";
//     public static final String ONENOTE_API = "https://www.onenote.com/api";
//     // Org
//     public static final String AUTHENTICATION_RESOURCE_ID = "https://onenote.com";
//     public static final String AUTHORITY_URL = "https://login.microsoftonline.com/common";
//     public static final String REDIRECT_URI = "<Your REDIRECT URI HERE>";
//     public static final String CLIENT_ID = "<Your CLIENT ID HERE>";
// }
// 
// Path: app/src/main/java/com/microsoft/o365_android_onenote_rest/util/SharedPrefsUtil.java
// public class SharedPrefsUtil {
// 
//     public static final String PREF_AUTH_TOKEN = "PREF_AUTH_TOKEN";
// 
//     public static SharedPreferences getSharedPreferences() {
//         return SnippetApp.getApp().getSharedPreferences(AppModule.PREFS, Context.MODE_PRIVATE);
//     }
// 
//     public static void persistAuthToken(AuthenticationResult result) {
//         setAccessToken(result.getAccessToken());
//         User.isOrg(true);
//     }
// 
//     public static void persistAuthToken(LiveConnectSession session) {
//         setAccessToken(session.getAccessToken());
//         User.isMsa(true);
//     }
// 
//     private static void setAccessToken(String accessToken) {
//         getSharedPreferences().edit().putString(PREF_AUTH_TOKEN, accessToken).commit();
//     }
// }
// 
// Path: app/src/main/java/com/microsoft/o365_android_onenote_rest/util/User.java
// public class User {
// 
//     private static final String PREF_MSA = "PREF_MSA";
//     private static final String PREF_ORG = "PREF_ORG";
// 
//     static void isMsa(boolean msa) {
//         set(PREF_MSA, msa);
//     }
// 
//     static void isOrg(boolean org) {
//         set(PREF_ORG, org);
//     }
// 
//     public static boolean isMsa() {
//         return is(PREF_MSA);
//     }
// 
//     public static boolean isOrg() {
//         return is(PREF_ORG);
//     }
// 
//     private static boolean is(String which) {
//         return SharedPrefsUtil.getSharedPreferences().getBoolean(which, false);
//     }
// 
//     private static void set(String which, boolean state) {
//         SharedPrefsUtil
//                 .getSharedPreferences()
//                 .edit()
//                 .putBoolean(which, state)
//                 .commit();
//     }
// }


import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import com.microsoft.aad.adal.AuthenticationCallback;
import com.microsoft.aad.adal.AuthenticationResult;
import com.microsoft.live.LiveAuthException;
import com.microsoft.live.LiveAuthListener;
import com.microsoft.live.LiveConnectSession;
import com.microsoft.live.LiveStatus;
import com.microsoft.o365_android_onenote_rest.conf.ServiceConstants;
import com.microsoft.o365_android_onenote_rest.util.SharedPrefsUtil;
import com.microsoft.o365_android_onenote_rest.util.User;
import java.net.URI;
import java.util.UUID;
import butterknife.ButterKnife;
import butterknife.OnClick;
import timber.log.Timber;
import static com.microsoft.o365_android_onenote_rest.R.id.msa_signin;
import static com.microsoft.o365_android_onenote_rest.R.id.o365_signin;
        try {
            authenticateOrganization();
        } catch (IllegalArgumentException e) {
            warnBadClient();
        }
    }

    private void warnBadClient() {
        Toast.makeText(this,
                R.string.warning_clientid_redirecturi_incorrect,
                Toast.LENGTH_LONG)
                .show();
    }

    private void authenticateOrganization() throws IllegalArgumentException {
        validateOrganizationArgs();
        if (!User.isOrg()) {
            mLiveAuthClient.logout(new LiveAuthListener() {
                @Override
                public void onAuthComplete(LiveStatus status,
                                           LiveConnectSession session,
                                           Object userState) {
                    mAuthenticationManager.connect(SignInActivity.this);
                }

                @Override
                public void onAuthError(LiveAuthException exception, Object userState) {
                    mAuthenticationManager.connect(SignInActivity.this);
                }
            });
// Path: app/src/main/java/com/microsoft/o365_android_onenote_rest/conf/ServiceConstants.java
// public class ServiceConstants {
// 
//     // MSA
//     public static final String MSA_CLIENT_ID = "<Your MSA CLIENT ID>";
//     public static final String ONENOTE_API = "https://www.onenote.com/api";
//     // Org
//     public static final String AUTHENTICATION_RESOURCE_ID = "https://onenote.com";
//     public static final String AUTHORITY_URL = "https://login.microsoftonline.com/common";
//     public static final String REDIRECT_URI = "<Your REDIRECT URI HERE>";
//     public static final String CLIENT_ID = "<Your CLIENT ID HERE>";
// }
// 
// Path: app/src/main/java/com/microsoft/o365_android_onenote_rest/util/SharedPrefsUtil.java
// public class SharedPrefsUtil {
// 
//     public static final String PREF_AUTH_TOKEN = "PREF_AUTH_TOKEN";
// 
//     public static SharedPreferences getSharedPreferences() {
//         return SnippetApp.getApp().getSharedPreferences(AppModule.PREFS, Context.MODE_PRIVATE);
//     }
// 
//     public static void persistAuthToken(AuthenticationResult result) {
//         setAccessToken(result.getAccessToken());
//         User.isOrg(true);
//     }
// 
//     public static void persistAuthToken(LiveConnectSession session) {
//         setAccessToken(session.getAccessToken());
//         User.isMsa(true);
//     }
// 
//     private static void setAccessToken(String accessToken) {
//         getSharedPreferences().edit().putString(PREF_AUTH_TOKEN, accessToken).commit();
//     }
// }
// 
// Path: app/src/main/java/com/microsoft/o365_android_onenote_rest/util/User.java
// public class User {
// 
//     private static final String PREF_MSA = "PREF_MSA";
//     private static final String PREF_ORG = "PREF_ORG";
// 
//     static void isMsa(boolean msa) {
//         set(PREF_MSA, msa);
//     }
// 
//     static void isOrg(boolean org) {
//         set(PREF_ORG, org);
//     }
// 
//     public static boolean isMsa() {
//         return is(PREF_MSA);
//     }
// 
//     public static boolean isOrg() {
//         return is(PREF_ORG);
//     }
// 
//     private static boolean is(String which) {
//         return SharedPrefsUtil.getSharedPreferences().getBoolean(which, false);
//     }
// 
//     private static void set(String which, boolean state) {
//         SharedPrefsUtil
//                 .getSharedPreferences()
//                 .edit()
//                 .putBoolean(which, state)
//                 .commit();
//     }
// }


// Path: app/src/main/java/com/microsoft/o365_android_onenote_rest/SignInActivity.java
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import com.microsoft.aad.adal.AuthenticationCallback;
import com.microsoft.aad.adal.AuthenticationResult;
import com.microsoft.live.LiveAuthException;
import com.microsoft.live.LiveAuthListener;
import com.microsoft.live.LiveConnectSession;
import com.microsoft.live.LiveStatus;
import com.microsoft.o365_android_onenote_rest.conf.ServiceConstants;
import com.microsoft.o365_android_onenote_rest.util.SharedPrefsUtil;
import com.microsoft.o365_android_onenote_rest.util.User;
import java.net.URI;
import java.util.UUID;
import butterknife.ButterKnife;
import butterknife.OnClick;
import timber.log.Timber;
import static com.microsoft.o365_android_onenote_rest.R.id.msa_signin;
import static com.microsoft.o365_android_onenote_rest.R.id.o365_signin;

        try {
            authenticateOrganization();
        } catch (IllegalArgumentException e) {
            warnBadClient();
        }
    }

    private void warnBadClient() {
        Toast.makeText(this,
                R.string.warning_clientid_redirecturi_incorrect,
                Toast.LENGTH_LONG)
                .show();
    }

    private void authenticateOrganization() throws IllegalArgumentException {
        validateOrganizationArgs();
        if (!User.isOrg()) {
            mLiveAuthClient.logout(new LiveAuthListener() {
                @Override
                public void onAuthComplete(LiveStatus status,
                                           LiveConnectSession session,
                                           Object userState) {
                    mAuthenticationManager.connect(SignInActivity.this);
                }

                @Override
                public void onAuthError(LiveAuthException exception, Object userState) {
                    mAuthenticationManager.connect(SignInActivity.this);
                }
            });
        } else {