├── app ├── .gitignore ├── gradle.properties ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable │ │ │ │ ├── test.jpg │ │ │ │ └── ic_launcher.xml │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── styles.xml │ │ │ │ └── strings.xml │ │ │ ├── menu │ │ │ │ └── send_mail.xml │ │ │ └── layout │ │ │ │ ├── activity_connect.xml │ │ │ │ └── activity_send_mail.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── microsoft │ │ │ │ └── graph │ │ │ │ └── connect │ │ │ │ ├── util │ │ │ │ ├── IManifestReader.java │ │ │ │ └── ManifestReader.java │ │ │ │ ├── TokenNotFoundException.java │ │ │ │ ├── MSALAuthenticationCallback.java │ │ │ │ ├── UiBehavior.java │ │ │ │ ├── Constants.java │ │ │ │ ├── Connect.java │ │ │ │ ├── GraphServiceClientManager.java │ │ │ │ ├── AuthenticationManager.java │ │ │ │ ├── ConnectActivity.java │ │ │ │ ├── SendMailActivity.java │ │ │ │ └── GraphServiceController.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── microsoft │ │ │ └── graph │ │ │ └── connect │ │ │ ├── ConfigurationTests.java │ │ │ ├── AuthenticationManagerUnitTests.java │ │ │ └── GraphServiceControllerUnitTests.java │ └── androidTest │ │ ├── getTestConfig.sh │ │ └── getTestConfig.bat ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── readme-images ├── aad-application-id.PNG ├── aad-implicit-grant.png ├── aad-register-an-app.PNG ├── Android-Connect-Constants.png ├── aad-portal-app-registrations.png ├── aad-redirect-uri-public-client.PNG └── O365-Android-Connect-video_play_icon.png ├── .gitignore ├── gradle.properties ├── NOTICES.md ├── LICENSE ├── gradlew.bat ├── README-Localized ├── README-zh-cn.md ├── README-zh-tw.md ├── README-ja-jp.md ├── README-pt-br.md ├── README-ru-ru.md ├── README-de-de.md ├── README-es-es.md └── README-fr-fr.md ├── gradlew ├── README.md └── CONTRIBUTING.md /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /app/gradle.properties: -------------------------------------------------------------------------------- 1 | test_client_id= 2 | test_username= 3 | test_password= 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-sample/master/app/src/main/res/drawable/test.jpg -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-sample/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /readme-images/aad-application-id.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-sample/master/readme-images/aad-application-id.PNG -------------------------------------------------------------------------------- /readme-images/aad-implicit-grant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-sample/master/readme-images/aad-implicit-grant.png -------------------------------------------------------------------------------- /readme-images/aad-register-an-app.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-sample/master/readme-images/aad-register-an-app.PNG -------------------------------------------------------------------------------- /readme-images/Android-Connect-Constants.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-sample/master/readme-images/Android-Connect-Constants.png -------------------------------------------------------------------------------- /readme-images/aad-portal-app-registrations.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-sample/master/readme-images/aad-portal-app-registrations.png -------------------------------------------------------------------------------- /readme-images/aad-redirect-uri-public-client.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-sample/master/readme-images/aad-redirect-uri-public-client.PNG -------------------------------------------------------------------------------- /readme-images/O365-Android-Connect-video_play_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-sample/master/readme-images/O365-Android-Connect-video_play_icon.png -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/graph/connect/util/IManifestReader.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.graph.connect.util; 2 | 3 | public interface IManifestReader { 4 | String getApplicationMetadataValueString(String key); 5 | } 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Apr 16 16:17:00 EAT 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.ap_ 2 | *.apk 3 | *.class 4 | *.dex 5 | *.iml 6 | *.ipr 7 | *.iws 8 | .DS_Store 9 | .classpath 10 | .gradle 11 | .idea 12 | .project 13 | /.idea/libraries 14 | /.idea/workspace.xml 15 | /build 16 | /captures 17 | /local.properties 18 | Thumbs.db 19 | bin/ 20 | build/ 21 | gen/ 22 | out/ 23 | testConfig.json 24 | -------------------------------------------------------------------------------- /app/src/test/java/com/microsoft/graph/connect/ConfigurationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See LICENSE in the project root for license information. 4 | */ 5 | package com.microsoft.graph.connect; 6 | 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.assertTrue; 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | #3F51B5 7 | #303F9F 8 | #FF4081 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/menu/send_mail.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 16dp 8 | 16dp 9 | 48dp 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/graph/connect/TokenNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See LICENSE in the project root for license information. 4 | */ 5 | package com.microsoft.graph.connect; 6 | 7 | /** 8 | * Exception to throw when a token is not available in Authentication Manager. 9 | */ 10 | public class TokenNotFoundException extends Exception { 11 | public TokenNotFoundException() { 12 | super(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/graph/connect/MSALAuthenticationCallback.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.graph.connect; 2 | 3 | import com.microsoft.identity.client.AuthenticationResult; 4 | import com.microsoft.identity.client.exception.MsalException; 5 | 6 | /** 7 | * Created by johnaustin on 7/5/17. 8 | */ 9 | 10 | interface MSALAuthenticationCallback { 11 | void onSuccess(AuthenticationResult authenticationResult); 12 | void onError(MsalException exception); 13 | void onError(Exception exception); 14 | void onCancel(); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/androidTest/getTestConfig.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | testConfig="{ 4 | \"test_client_id\": \"$TEST_CLIENT_ID\", 5 | \"test_username\": \"$TEST_USERNAME\", 6 | \"test_password\": \"$1\" 7 | }" 8 | echo $testConfig 9 | echo $testConfig > testConfig.json 10 | 11 | adb devices | while read line 12 | do 13 | if [ ! "$line" = "" ] && [ `echo $line | awk '{print $2}'` = "device" ] 14 | then 15 | device=`echo $line | awk '{print $1}'` 16 | echo "$device $@ ..." 17 | adb -s $device push testConfig.json ./data/local 18 | fi 19 | done 20 | -------------------------------------------------------------------------------- /app/src/androidTest/getTestConfig.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | SET testConfig={ 4 | SET testConfig=%testConfig% "test_client_id": "%TEST_CLIENT_ID%", 5 | SET testConfig=%testConfig% "test_username": "%TEST_USERNAME%", 6 | SET testConfig=%testConfig% "test_password": "%1" 7 | SET testConfig=%testConfig% } 8 | echo %testConfig% 9 | echo %testConfig% > testConfig.json 10 | 11 | SET _adb_devices=%ANDROID_HOME%\platform-tools\adb.exe devices 12 | FOR /f "skip=1" %%G IN ('%_adb_devices%') DO %ANDROID_HOME%\platform-tools\adb.exe -s %%G push testConfig.json ./data/local 13 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/test/java/com/microsoft/graph/connect/AuthenticationManagerUnitTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See LICENSE in the project root for license information. 4 | */ 5 | package com.microsoft.graph.connect; 6 | 7 | import org.junit.Test; 8 | 9 | /** 10 | * Unit tests for the AuthenticationManager class. 11 | */ 12 | public class AuthenticationManagerUnitTests { 13 | @Test(expected = TokenNotFoundException.class) 14 | public void getAccessToken_noTokenAvailable() throws Exception { 15 | AuthenticationManager.getInstance().getAccessToken(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/ricalo/Android/Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/graph/connect/UiBehavior.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.graph.connect; 2 | 3 | /** 4 | * The UI options that developer could pass in during interactive sign in. 5 | */ 6 | 7 | public enum UiBehavior { 8 | 9 | /** 10 | * AcquireToken will send prompt=select_account to authorize endpoint and would show a list of users from which can be 11 | * selected for authentication. 12 | */ 13 | SELECT_ACCOUNT, 14 | 15 | /** 16 | * The user will be prompted for credentials by the service. It is achieved by sending prompt=login to the service. 17 | */ 18 | FORCE_LOGIN, 19 | 20 | /** 21 | * The user will be prompted to consent even if consent was granted before. It is achieved by sending prompt=consent 22 | * to the service. 23 | */ 24 | CONSENT 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/graph/connect/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See LICENSE in the project root for license information. 4 | */ 5 | package com.microsoft.graph.connect; 6 | 7 | public class Constants { 8 | public static final String AUTHORITY_URL = "https://login.microsoftonline.com/common"; 9 | public static final String AUTHORIZATION_ENDPOINT = "/oauth2/v2.0/authorize"; 10 | public static final String TOKEN_ENDPOINT = "/oauth2/v2.0/token"; 11 | // The Microsoft Graph delegated permissions that you set in the application 12 | // registration portal must match these scope values. 13 | // Update this constant with the scope (permission) values for your application: 14 | public static final String[] SCOPES = {"openid", "Mail.ReadWrite","mail.send","Files.ReadWrite","User.ReadBasic.All"}; 15 | } 16 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /NOTICES.md: -------------------------------------------------------------------------------- 1 | This project includes the following third-party components: 2 | 3 | 4 | Microsoft Azure Active Directory Authentication Library (ADAL) for Android, which is Copyright (c) Microsoft Open Technologies, Inc., and is available under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0). Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 5 | 6 | Microsoft Graph SDK for Android, which is Copyright (c) Microsoft Corporation, and is available under the [MIT License](https://github.com/microsoftgraph/msgraph-sdk-android/blob/master/LICENSE). 7 | 8 | Android SDK, which is provided by the Android Open Source Project and is used according to terms described in the [Creative Commons 2.5 Attribution License](http://creativecommons.org/licenses/by/2.5/). The Android SDK is available at [http://developer.android.com/sdk/index.html](http://developer.android.com/sdk/index.html). 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Microsoft. All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/graph/connect/util/ManifestReader.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.graph.connect.util; 2 | 3 | 4 | import android.content.pm.PackageInfo; 5 | import android.content.pm.PackageManager; 6 | import android.os.Bundle; 7 | 8 | import com.microsoft.graph.connect.Connect; 9 | 10 | 11 | /* 12 | Contains methods that access the application manifest 13 | */ 14 | public class ManifestReader implements IManifestReader{ 15 | 16 | /** 17 | * Gets the value of an AndroidManifest meta-data node. If the node value cannot be cast to String, 18 | * null is returned. 19 | * @param key String. The meta-data key value 20 | * @return String. The value associated with the key 21 | */ 22 | @Override 23 | public String getApplicationMetadataValueString(String key) { 24 | String returnValue = ""; 25 | try { 26 | PackageInfo info = Connect.getContext().getPackageManager().getPackageInfo( 27 | Connect.getContext().getPackageName(), 28 | PackageManager.GET_META_DATA); 29 | if (info.applicationInfo.metaData != null) { 30 | Bundle bundle = info.applicationInfo.metaData; 31 | returnValue = bundle.getString(key); 32 | } 33 | } catch (Exception e) { 34 | e.printStackTrace(); 35 | } 36 | return returnValue; 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /app/src/test/java/com/microsoft/graph/connect/GraphServiceControllerUnitTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See LICENSE in the project root for license information. 4 | */ 5 | package com.microsoft.graph.connect; 6 | 7 | import com.microsoft.graph.extensions.Message; 8 | 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | 12 | import static org.junit.Assert.assertNotNull; 13 | 14 | /** 15 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 16 | */ 17 | public class GraphServiceControllerUnitTests { 18 | 19 | private GraphServiceController graphServiceController; 20 | 21 | @Before 22 | public void createGraphServiceController() { 23 | graphServiceController = new GraphServiceController(); 24 | } 25 | 26 | @Test 27 | public void createMessage_messageNotNull() throws Exception { 28 | Message message = graphServiceController.createMessage( 29 | "Fictitious Subject", 30 | "Fictitious Body", 31 | "fictitiousEmail@contoso.com" 32 | ); 33 | 34 | assertNotNull(message); 35 | } 36 | 37 | @Test(expected = IllegalArgumentException.class) 38 | public void createMessage_addressNotNull() throws Exception { 39 | graphServiceController.createMessage( 40 | "Fictitious Subject", 41 | "Fictitious Body", 42 | null 43 | ); 44 | } 45 | 46 | @Test(expected = IllegalArgumentException.class) 47 | public void createMessage_addressNotEmpty() throws Exception { 48 | graphServiceController.createMessage( 49 | "Fictitious Subject", 50 | "Fictitious Body", 51 | "" 52 | ); 53 | } 54 | 55 | @Test(expected = IllegalArgumentException.class) 56 | public void createMessage_wellFormedAddress() throws Exception { 57 | graphServiceController.createMessage( 58 | "Fictitious Subject", 59 | "Fictitious Body", 60 | "Invalid@Address" 61 | ); 62 | } 63 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_connect.xml: -------------------------------------------------------------------------------- 1 | 5 | 15 | 16 |