├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable-mdpi │ │ │ │ ├── mail_icon.png │ │ │ │ └── ic_launcher.png │ │ │ ├── values │ │ │ │ ├── styles.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── identifiers.xml │ │ │ │ └── strings.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ ├── menu │ │ │ │ └── send_mail.xml │ │ │ └── layout │ │ │ │ ├── activity_connect.xml │ │ │ │ └── activity_send_mail.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── microsoft │ │ │ │ └── office365 │ │ │ │ └── connectmicrosoftgraph │ │ │ │ ├── AuthenticationCallback.java │ │ │ │ ├── vo │ │ │ │ ├── EmailAddressVO.java │ │ │ │ ├── ToRecipientsVO.java │ │ │ │ ├── BodyVO.java │ │ │ │ ├── MessageWrapper.java │ │ │ │ └── MessageVO.java │ │ │ │ ├── MSGraphAPIService.java │ │ │ │ ├── Constants.java │ │ │ │ ├── MSGraphAPIController.java │ │ │ │ ├── RESTHelper.java │ │ │ │ ├── SendMailActivity.java │ │ │ │ ├── AuthenticationManager.java │ │ │ │ └── ConnectActivity.java │ │ └── AndroidManifest.xml │ └── test │ │ └── java │ │ └── com │ │ └── microsoft │ │ └── office365 │ │ └── connectmicrosoftgraph │ │ └── ConnectUnitTests.java ├── proguard-rules.pro ├── dailyBuild.gradle └── build.gradle ├── oidclib ├── .gitignore ├── src │ ├── main │ │ ├── assets │ │ │ └── Roboto-BoldCondensed.ttf │ │ ├── res │ │ │ ├── drawable │ │ │ │ ├── ic_account_authenticator.png │ │ │ │ └── ic_small_account_authenticator.png │ │ │ ├── drawable-mdpi │ │ │ │ ├── ic_account_authenticator.png │ │ │ │ └── ic_small_account_authenticator.png │ │ │ ├── drawable-xhdpi │ │ │ │ ├── ic_account_authenticator.png │ │ │ │ └── ic_small_account_authenticator.png │ │ │ ├── drawable-xxhdpi │ │ │ │ ├── ic_account_authenticator.png │ │ │ │ └── ic_small_account_authenticator.png │ │ │ ├── color │ │ │ │ ├── primary_text_sel.xml │ │ │ │ ├── primary_text_inv_sel.xml │ │ │ │ ├── secondary_text_sel.xml │ │ │ │ ├── secondary_text_inv_sel.xml │ │ │ │ └── oidc_button_color_selector.xml │ │ │ ├── layout │ │ │ │ ├── spinner_selected_item.xml │ │ │ │ ├── spinner_dropdown_item.xml │ │ │ │ ├── activity_authentication.xml │ │ │ │ └── activity_clientconfiguration.xml │ │ │ ├── xml │ │ │ │ └── authenticator.xml │ │ │ └── values │ │ │ │ ├── dimens.xml │ │ │ │ ├── identifiers.xml │ │ │ │ ├── oidc_endpoints.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ ├── theme.xml │ │ │ │ ├── oidc_clientoptions.xml │ │ │ │ ├── oidc_clientconf.xml │ │ │ │ └── styles.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── lnikkila │ │ │ │ └── oidc │ │ │ │ ├── security │ │ │ │ ├── UserNotAuthenticatedWrapperException.java │ │ │ │ ├── AccountSensitiveDataStorageUtils.java │ │ │ │ ├── SensitiveDataUtils.java │ │ │ │ ├── SensitiveDataPreApi23.java │ │ │ │ └── SensitiveDataPostApi23.java │ │ │ │ ├── authenticator │ │ │ │ ├── AuthenticatorService.java │ │ │ │ └── Authenticator.java │ │ │ │ ├── minsdkcompat │ │ │ │ ├── CompatEditText.java │ │ │ │ ├── CompatTextView.java │ │ │ │ └── CompatUri.java │ │ │ │ └── OIDCAccountManager.java │ │ └── AndroidManifest.xml │ └── androidTest │ │ └── java │ │ └── com │ │ └── lnikkila │ │ └── oidc │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── readme-images ├── O365-Android-Connect-Constants.png ├── O365-Android-Connect-video_play_icon.png └── o365-android-microsoft-graph-permissions.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-es-es.md ├── README-ru-ru.md ├── README-de-de.md └── README-fr-fr.md ├── gradlew └── README.md /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /oidclib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | include ':oidclib' -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-rest-sample/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/mail_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-rest-sample/master/app/src/main/res/drawable-mdpi/mail_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-rest-sample/master/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /oidclib/src/main/assets/Roboto-BoldCondensed.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-rest-sample/master/oidclib/src/main/assets/Roboto-BoldCondensed.ttf -------------------------------------------------------------------------------- /readme-images/O365-Android-Connect-Constants.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-rest-sample/master/readme-images/O365-Android-Connect-Constants.png -------------------------------------------------------------------------------- /readme-images/O365-Android-Connect-video_play_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-rest-sample/master/readme-images/O365-Android-Connect-video_play_icon.png -------------------------------------------------------------------------------- /oidclib/src/main/res/drawable/ic_account_authenticator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-rest-sample/master/oidclib/src/main/res/drawable/ic_account_authenticator.png -------------------------------------------------------------------------------- /readme-images/o365-android-microsoft-graph-permissions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-rest-sample/master/readme-images/o365-android-microsoft-graph-permissions.png -------------------------------------------------------------------------------- /oidclib/src/main/res/drawable-mdpi/ic_account_authenticator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-rest-sample/master/oidclib/src/main/res/drawable-mdpi/ic_account_authenticator.png -------------------------------------------------------------------------------- /oidclib/src/main/res/drawable-xhdpi/ic_account_authenticator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-rest-sample/master/oidclib/src/main/res/drawable-xhdpi/ic_account_authenticator.png -------------------------------------------------------------------------------- /oidclib/src/main/res/drawable/ic_small_account_authenticator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-rest-sample/master/oidclib/src/main/res/drawable/ic_small_account_authenticator.png -------------------------------------------------------------------------------- /oidclib/src/main/res/drawable-xxhdpi/ic_account_authenticator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-rest-sample/master/oidclib/src/main/res/drawable-xxhdpi/ic_account_authenticator.png -------------------------------------------------------------------------------- /oidclib/src/main/res/drawable-mdpi/ic_small_account_authenticator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-rest-sample/master/oidclib/src/main/res/drawable-mdpi/ic_small_account_authenticator.png -------------------------------------------------------------------------------- /oidclib/src/main/res/drawable-xhdpi/ic_small_account_authenticator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-rest-sample/master/oidclib/src/main/res/drawable-xhdpi/ic_small_account_authenticator.png -------------------------------------------------------------------------------- /oidclib/src/main/res/drawable-xxhdpi/ic_small_account_authenticator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-connect-rest-sample/master/oidclib/src/main/res/drawable-xxhdpi/ic_small_account_authenticator.png -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Oct 18 10:07:36 PDT 2016 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-2.14.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 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 48dp 6 | 7 | -------------------------------------------------------------------------------- /oidclib/src/main/res/color/primary_text_sel.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /oidclib/src/main/res/color/primary_text_inv_sel.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /oidclib/src/main/res/color/secondary_text_sel.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /oidclib/src/main/res/color/secondary_text_inv_sel.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /oidclib/src/main/res/layout/spinner_selected_item.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /oidclib/src/main/res/xml/authenticator.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/office365/connectmicrosoftgraph/AuthenticationCallback.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.office365.connectmicrosoftgraph; 6 | 7 | interface AuthenticationCallback { 8 | void onSuccess(T data); 9 | void onError(Exception e); 10 | } 11 | -------------------------------------------------------------------------------- /oidclib/src/main/res/layout/spinner_dropdown_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /oidclib/src/androidTest/java/com/lnikkila/oidc/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.lnikkila.oidc; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/office365/connectmicrosoftgraph/vo/EmailAddressVO.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.office365.connectmicrosoftgraph.vo; 6 | 7 | import com.google.gson.annotations.SerializedName; 8 | 9 | public class EmailAddressVO { 10 | 11 | @SerializedName("Address") 12 | public String mAddress; 13 | 14 | } -------------------------------------------------------------------------------- /oidclib/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 0.26 4 | 0.30 5 | 0.30 6 | 0.30 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/office365/connectmicrosoftgraph/vo/ToRecipientsVO.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.office365.connectmicrosoftgraph.vo; 6 | 7 | import com.google.gson.annotations.SerializedName; 8 | 9 | public class ToRecipientsVO { 10 | 11 | @SerializedName("EmailAddress") 12 | public EmailAddressVO emailAddress; 13 | 14 | } -------------------------------------------------------------------------------- /oidclib/src/main/res/values/identifiers.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | com.lnikkila.oidclib.account 9 | 10 | 11 | OIDC Android Client 12 | 13 | 14 | -------------------------------------------------------------------------------- /oidclib/src/main/java/com/lnikkila/oidc/security/UserNotAuthenticatedWrapperException.java: -------------------------------------------------------------------------------- 1 | package com.lnikkila.oidc.security; 2 | 3 | /** 4 | * Wrapper for {@link android.security.keystore.UserNotAuthenticatedException} because it does not 5 | * exist in pre M APIs. 6 | * Created by Camilo Montes on 20/01/2016. 7 | */ 8 | public class UserNotAuthenticatedWrapperException extends Exception { 9 | 10 | public UserNotAuthenticatedWrapperException(Throwable throwable) { 11 | super(throwable); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /oidclib/src/main/res/color/oidc_button_color_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/office365/connectmicrosoftgraph/vo/BodyVO.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.office365.connectmicrosoftgraph.vo; 6 | 7 | import com.google.gson.annotations.SerializedName; 8 | 9 | public class BodyVO { 10 | 11 | @SerializedName("ContentType") 12 | public String mContentType; 13 | 14 | @SerializedName("Content") 15 | public String mContent; 16 | 17 | } -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/office365/connectmicrosoftgraph/vo/MessageWrapper.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.office365.connectmicrosoftgraph.vo; 6 | 7 | import com.google.gson.annotations.SerializedName; 8 | 9 | public class MessageWrapper { 10 | 11 | @SerializedName("Message") 12 | public MessageVO mMessage; 13 | 14 | public MessageWrapper(MessageVO msg) { 15 | mMessage = msg; 16 | } 17 | } -------------------------------------------------------------------------------- /oidclib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /oidclib/src/main/res/values/oidc_endpoints.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | example 5 | https://login.microsoftonline.com/common/oauth2/v2.0/authorize 6 | https://login.microsoftonline.com/common/oauth2/v2.0/token 7 | https://graph.microsoft.com/v1.0/me 8 | https://www.example.com/oauth2/revoketoken 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/identifiers.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | com.microsoft.graph.connect.account 9 | 10 | 11 | Connect Sample Account 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/office365/connectmicrosoftgraph/vo/MessageVO.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.office365.connectmicrosoftgraph.vo; 6 | 7 | import com.google.gson.annotations.SerializedName; 8 | 9 | /** 10 | * Mail Value Object for holding values in an email 11 | */ 12 | public class MessageVO { 13 | 14 | @SerializedName("Subject") 15 | public String mSubject; 16 | 17 | @SerializedName("Body") 18 | public BodyVO mBody; 19 | 20 | @SerializedName("ToRecipients") 21 | public ToRecipientsVO[] mToRecipients; 22 | 23 | } -------------------------------------------------------------------------------- /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 C:\Program Files (x86)\Android\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/office365/connectmicrosoftgraph/MSGraphAPIService.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.office365.connectmicrosoftgraph; 6 | 7 | import com.microsoft.office365.connectmicrosoftgraph.vo.MessageWrapper; 8 | 9 | import retrofit2.Call; 10 | import retrofit2.http.Body; 11 | import retrofit2.http.Header; 12 | import retrofit2.http.POST; 13 | 14 | 15 | public interface MSGraphAPIService { 16 | @POST("/v1.0/me/microsoft.graph.sendmail") 17 | Call sendMail( 18 | @Header("Content-type") String contentTypeHeader, 19 | @Body MessageWrapper mail); 20 | } -------------------------------------------------------------------------------- /oidclib/src/main/java/com/lnikkila/oidc/authenticator/AuthenticatorService.java: -------------------------------------------------------------------------------- 1 | package com.lnikkila.oidc.authenticator; 2 | 3 | import android.app.Service; 4 | import android.content.Intent; 5 | import android.os.IBinder; 6 | import android.util.Log; 7 | 8 | /** 9 | * The service that lets Android know about the custom Authenticator. 10 | * 11 | * @author Leo Nikkilä 12 | */ 13 | public class AuthenticatorService extends Service { 14 | 15 | private final String TAG = getClass().getSimpleName(); 16 | 17 | @Override 18 | public IBinder onBind(Intent intent) { 19 | Log.d(TAG, "Binding Authenticator."); 20 | 21 | Authenticator authenticator = new Authenticator(this); 22 | return authenticator.getIBinder(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /oidclib/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFC107 4 | #FFA000 5 | #FF6F00 6 | #fafafa 7 | #000000 8 | #000000 9 | #de000000 10 | #ffffff 11 | #9e9c9c 12 | #8a000000 13 | #8a000000 14 | #b3ffffff 15 | #b3ffffff 16 | #FFFFFF 17 | #a8a8a8 18 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /oidclib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | OIDC Android Client 3 | 4 | Use OAuth2 only 5 | Client Id 6 | Client Password 7 | Redirect URL 8 | Issuer 9 | Scopes (separed by space) 10 | Flow Type %1$s 11 | SAVE CHANCES 12 | 13 | Username 14 | Password 15 | LOG IN 16 | 17 | Mandatory 18 | 19 | -------------------------------------------------------------------------------- /oidclib/src/main/java/com/lnikkila/oidc/minsdkcompat/CompatEditText.java: -------------------------------------------------------------------------------- 1 | package com.lnikkila.oidc.minsdkcompat; 2 | 3 | import android.content.Context; 4 | import android.graphics.Typeface; 5 | import android.support.v7.widget.AppCompatEditText; 6 | import android.util.AttributeSet; 7 | 8 | /** 9 | * 10 | * @author Camilo Montes 11 | */ 12 | public class CompatEditText extends AppCompatEditText { 13 | 14 | public CompatEditText(Context context, AttributeSet attrs, int defStyle) { 15 | super(context, attrs, defStyle); 16 | createFont(); 17 | } 18 | 19 | public CompatEditText(Context context, AttributeSet attrs) { 20 | super(context, attrs); 21 | createFont(); 22 | } 23 | 24 | public CompatEditText(Context context) { 25 | super(context); 26 | createFont(); 27 | } 28 | 29 | public void createFont() { 30 | Typeface font = Typeface.createFromAsset(getContext().getAssets(), "Roboto-BoldCondensed.ttf"); 31 | setTypeface(font); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /oidclib/src/main/java/com/lnikkila/oidc/minsdkcompat/CompatTextView.java: -------------------------------------------------------------------------------- 1 | package com.lnikkila.oidc.minsdkcompat; 2 | 3 | import android.content.Context; 4 | import android.graphics.Typeface; 5 | import android.support.v7.widget.AppCompatTextView; 6 | import android.util.AttributeSet; 7 | import android.widget.TextView; 8 | 9 | /** 10 | * 11 | * @author Camilo Montes 12 | */ 13 | public class CompatTextView extends AppCompatTextView { 14 | public CompatTextView(Context context, AttributeSet attrs, int defStyle) { 15 | super(context, attrs, defStyle); 16 | createFont(); 17 | } 18 | 19 | public CompatTextView(Context context, AttributeSet attrs) { 20 | super(context, attrs); 21 | createFont(); 22 | } 23 | 24 | public CompatTextView(Context context) { 25 | super(context); 26 | createFont(); 27 | } 28 | 29 | public void createFont() { 30 | Typeface font = Typeface.createFromAsset(getContext().getAssets(), "Roboto-BoldCondensed.ttf"); 31 | setTypeface(font); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/office365/connectmicrosoftgraph/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.office365.connectmicrosoftgraph; 6 | 7 | 8 | /* 9 | These constant values configure the client app to use OAuth2 and open id connect 10 | to authenticate with Azure and authorize the app to access the specified scopes. 11 | Read more about scopes: https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-scopes 12 | */ 13 | interface Constants { 14 | String AUTHORITY_URL = "https://login.microsoftonline.com/common"; 15 | // Update these two constants with the values for your application: 16 | String CLIENT_ID = "ENTER_YOUR_CLIENT_ID"; 17 | String REDIRECT_URI = "https://login.microsoftonline.com/common/oauth2/nativeclient"; 18 | String MICROSOFT_GRAPH_API_ENDPOINT_RESOURCE_ID = "https://graph.microsoft.com/"; 19 | String SCOPES = "openid profile User.Read Mail.Send offline_access"; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /app/dailyBuild.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | applicationId "com.microsoft.office365.connect" 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFile 'proguard-rules.pro' 18 | } 19 | } 20 | lintOptions { 21 | disable 'InvalidPackage' 22 | } 23 | } 24 | 25 | dependencies { 26 | compile fileTree(dir: 'libs', include: ['*.jar']) 27 | compile 'com.android.support:appcompat-v7:+' 28 | 29 | // OIDCAndroidLib 30 | compile project(':oidclib') 31 | 32 | // Retrofit + custom HTTP 33 | compile 'com.squareup.okhttp3:okhttp:+' 34 | compile 'com.squareup.okhttp3:logging-interceptor:+' 35 | compile 'com.squareup.retrofit2:retrofit:+' 36 | compile 'com.squareup.retrofit2:converter-gson:+' 37 | 38 | // Test 39 | testCompile 'junit:junit:+' 40 | } 41 | -------------------------------------------------------------------------------- /NOTICES.md: -------------------------------------------------------------------------------- 1 | This project includes the following third-party components: 2 | 3 | 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). 4 | 5 | OIDCAndroidLib 6 | Copyright (c) 2015, Camilo Montes 7 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 9 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.microsoft.office365.connect" 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFile 'proguard-rules.pro' 18 | } 19 | } 20 | lintOptions { 21 | disable 'InvalidPackage' 22 | } 23 | } 24 | 25 | dependencies { 26 | compile fileTree(dir: 'libs', include: ['*.jar']) 27 | compile 'com.android.support:appcompat-v7:23.3.0' 28 | 29 | // OIDCAndroidLib 30 | compile project(':oidclib') 31 | 32 | // Retrofit + custom HTTP 33 | compile 'com.squareup.okhttp3:okhttp:3.3.1' 34 | compile 'com.squareup.okhttp3:logging-interceptor:3.3.1' 35 | compile 'com.squareup.retrofit2:retrofit:2.1.0' 36 | compile 'com.squareup.retrofit2:converter-gson:2.1.0' 37 | 38 | // Test 39 | testCompile 'junit:junit:4.12' 40 | } 41 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /oidclib/src/main/res/values/theme.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 22 | -------------------------------------------------------------------------------- /oidclib/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 /Applications/Android Studio.app/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 | 19 | # Needed to keep generic types and @Key annotations accessed via reflection 20 | -keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault 21 | -keepclassmembers class * { 22 | @com.google.api.client.util.Key ; 23 | } 24 | 25 | # Needed by google-http-client-android when linking against an older platform version 26 | -dontwarn com.google.api.client.extensions.android.** 27 | 28 | # Needed by google-api-client-android when linking against an older platform version 29 | -dontwarn com.google.api.client.googleapis.extensions.android.** 30 | 31 | # Needed by google-play-services when linking against an older platform version 32 | -dontwarn com.google.android.gms.** 33 | -dontnote com.google.android.gms.** 34 | 35 | # com.google.client.util.IOUtils references java.nio.file.Files when on Java 7+ 36 | -dontnote java.nio.file.Files, java.nio.file.Path 37 | 38 | # Suppress notes on LicensingServices 39 | -dontnote **.ILicensingService 40 | 41 | # Suppress warnings on sun.misc.Unsafe 42 | -dontnote sun.misc.Unsafe 43 | -dontwarn sun.misc.Unsafe 44 | -------------------------------------------------------------------------------- /app/src/main/res/menu/send_mail.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 36 | -------------------------------------------------------------------------------- /oidclib/src/main/java/com/lnikkila/oidc/minsdkcompat/CompatUri.java: -------------------------------------------------------------------------------- 1 | package com.lnikkila.oidc.minsdkcompat; 2 | 3 | import android.annotation.TargetApi; 4 | import android.net.Uri; 5 | import android.os.Build; 6 | 7 | import java.util.Collections; 8 | import java.util.LinkedHashSet; 9 | import java.util.Set; 10 | 11 | /** 12 | * Created by CQX342 on 12/06/2015. 13 | * @see "http://stackoverflow.com/a/12081355" 14 | */ 15 | public class CompatUri { 16 | /** 17 | * Error message presented when a user tries to treat an opaque URI as 18 | * hierarchical. 19 | */ 20 | private static final String NOT_HIERARCHICAL 21 | = "This isn't a hierarchical URI."; 22 | 23 | /** 24 | * Returns a set of the unique names of all query parameters. Iterating 25 | * over the set will return the names in order of their first occurrence. 26 | * Extracted from Uri#getQueryParameterNames() API 22. 27 | * 28 | * @throws UnsupportedOperationException if this isn't a hierarchical URI 29 | * @see Uri#getQueryParameterNames() 30 | * 31 | * @return a set of decoded names 32 | */ 33 | @TargetApi(Build.VERSION_CODES.GINGERBREAD) 34 | public static Set getQueryParameterNames(Uri uri) { 35 | if (uri.isOpaque()) { 36 | throw new UnsupportedOperationException(NOT_HIERARCHICAL); 37 | } 38 | 39 | String query = uri.getEncodedQuery(); 40 | if (query == null) { 41 | return Collections.emptySet(); 42 | } 43 | 44 | Set names = new LinkedHashSet<>(); 45 | int start = 0; 46 | do { 47 | int next = query.indexOf('&', start); 48 | int end = (next == -1) ? query.length() : next; 49 | 50 | int separator = query.indexOf('=', start); 51 | if (separator > end || separator == -1) { 52 | separator = end; 53 | } 54 | 55 | String name = query.substring(start, separator); 56 | names.add(Uri.decode(name)); 57 | 58 | // Move start to end of name. 59 | start = end + 1; 60 | } while (start < query.length()); 61 | 62 | return Collections.unmodifiableSet(names); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /oidclib/src/main/res/values/oidc_clientoptions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | prompt|login 12 | 14 | access_type|offline 15 | 16 | 17 | 19 | oidcEncryptionKey 20 | 21 | 24 | false 25 | 26 | 29 | 0 30 | 31 | 33 | true 34 | -------------------------------------------------------------------------------- /oidclib/src/main/res/values/oidc_clientconf.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 10 | true 11 | 12 | 13 | 7de59867-868d-44c3-ad29-c035bc3a680d 14 | 15 | 16 | 19 | https://login.microsoftonline.com/common/oauth2/nativeclient 20 | 21 | 25 | 26 | openid 27 | profile 28 | User.Read 29 | Mail.Send 30 | https://graph.microsoft.com/User.ReadBasic.All 31 | offline_access 32 | 33 | 34 | 38 | Code 39 | 40 | 43 | https://example.com 44 | -------------------------------------------------------------------------------- /oidclib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion '23.0.2' 6 | 7 | defaultConfig { 8 | minSdkVersion 9 9 | targetSdkVersion 23 10 | versionCode 2 11 | versionName "1.1" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(dir: 'libs', include: ['*.jar']) 23 | // For backwards compatibility, not necessarily needed 24 | compile 'com.android.support:appcompat-v7:23.1.1' 25 | compile 'com.android.support:design:23.1.1' 26 | 27 | // Google's OAuth library for OpenID Connect 28 | // See https://code.google.com/p/google-oauth-java-client/wiki/Setup 29 | compile('com.google.oauth-client:google-oauth-client:1.21.0') { 30 | exclude group: 'com.google.http-client', module: 'google-http-client' 31 | exclude group: 'com.google.code.findbugs', module: 'jsr305' 32 | exclude group: 'com.google.http-client', module: 'google-http-client-jackson' 33 | exclude group: 'junit', module: 'junit' 34 | exclude group: 'com.google.guava', module: 'guava-jdk5' 35 | exclude group: 'org.apache.httpcomponents', module: 'httpclient' 36 | } 37 | // Google's JSON parsing, could be replaced with Jackson 38 | compile('com.google.api-client:google-api-client-gson:1.21.0') { 39 | exclude group: 'com.google.api-client', module: 'google-api-client' 40 | exclude group: 'com.google.code.findbugs', module: 'jsr305' 41 | exclude group: 'org.apache.httpcomponents', module: 'httpclient' 42 | } 43 | // For backwards compatibility, not necessarily needed 44 | compile('com.google.api-client:google-api-client-android:1.21.0') { 45 | exclude group: 'com.google.android', module: 'android' 46 | exclude group: 'com.google.code.findbugs', module: 'jsr305' 47 | exclude group: 'com.google.guava', module: 'guava-jdk5' 48 | exclude group: 'junit', module: 'junit' 49 | exclude group: 'org.apache.httpcomponents', module: 'httpclient' 50 | exclude group: 'com.google.http-client', module: 'google-http-client-jackson2' 51 | } 52 | 53 | // Easier HTTP requests, not necessarily needed 54 | compile('com.github.kevinsawicki:http-request:6.0') { 55 | exclude group: 'junit', module: 'junit' 56 | } 57 | 58 | // Encryption for Pre Loli devices 59 | compile 'com.madgag.spongycastle:core:1.54.0.0' 60 | } 61 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/office365/connectmicrosoftgraph/MSGraphAPIController.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.office365.connectmicrosoftgraph; 6 | 7 | import android.content.Context; 8 | 9 | import com.microsoft.office365.connectmicrosoftgraph.vo.BodyVO; 10 | import com.microsoft.office365.connectmicrosoftgraph.vo.EmailAddressVO; 11 | import com.microsoft.office365.connectmicrosoftgraph.vo.MessageVO; 12 | import com.microsoft.office365.connectmicrosoftgraph.vo.MessageWrapper; 13 | import com.microsoft.office365.connectmicrosoftgraph.vo.ToRecipientsVO; 14 | 15 | import okhttp3.Interceptor; 16 | import retrofit2.Call; 17 | 18 | 19 | /** 20 | * Handles the creation of the message and contacting the 21 | * mail service to send the message. The app must have 22 | * connected to Office 365 and discovered the mail service 23 | * endpoints before using the createDraftMail method. 24 | */ 25 | public class MSGraphAPIController { 26 | 27 | private MSGraphAPIService mMSGraphAPIService; 28 | 29 | public MSGraphAPIController(Context context) { 30 | mMSGraphAPIService = new RESTHelper() 31 | .getRetrofit(context) 32 | .create(MSGraphAPIService.class); 33 | } 34 | 35 | public MSGraphAPIController(Interceptor interceptor) { 36 | mMSGraphAPIService = new RESTHelper() 37 | .getRetrofit(interceptor) 38 | .create(MSGraphAPIService.class); 39 | } 40 | 41 | /** 42 | * Sends an email message using the Microsoft Graph API on Office 365. The mail is sent 43 | * from the address of the signed in user. 44 | * 45 | * @param emailAddress The recipient email address. 46 | * @param subject The subject to use in the mail message. 47 | * @param body The body of the message. 48 | */ 49 | public Call sendMail( 50 | final String emailAddress, 51 | final String subject, 52 | final String body) { 53 | // create the email 54 | MessageWrapper msg = createMailPayload(subject, body, emailAddress); 55 | 56 | // send it using our service 57 | return mMSGraphAPIService.sendMail("application/json", msg); 58 | } 59 | 60 | private MessageWrapper createMailPayload( 61 | String subject, 62 | String body, 63 | String address) { 64 | EmailAddressVO emailAddressVO = new EmailAddressVO(); 65 | emailAddressVO.mAddress = address; 66 | 67 | ToRecipientsVO toRecipientsVO = new ToRecipientsVO(); 68 | toRecipientsVO.emailAddress = emailAddressVO; 69 | 70 | BodyVO bodyVO = new BodyVO(); 71 | bodyVO.mContentType = "HTML"; 72 | bodyVO.mContent = body; 73 | 74 | MessageVO sampleMsg = new MessageVO(); 75 | sampleMsg.mSubject = subject; 76 | sampleMsg.mBody = bodyVO; 77 | sampleMsg.mToRecipients = new ToRecipientsVO[]{toRecipientsVO}; 78 | 79 | return new MessageWrapper(sampleMsg); 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /oidclib/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 22 | 23 | 34 | 35 | 47 | 48 | 54 | 55 | 58 | 59 | 63 | 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/office365/connectmicrosoftgraph/RESTHelper.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.office365.connectmicrosoftgraph; 6 | 7 | import android.accounts.AuthenticatorException; 8 | import android.accounts.OperationCanceledException; 9 | import android.content.Context; 10 | import android.util.Log; 11 | 12 | import com.lnikkila.oidc.security.UserNotAuthenticatedWrapperException; 13 | 14 | import java.io.IOException; 15 | 16 | import okhttp3.Interceptor; 17 | import okhttp3.OkHttpClient; 18 | import okhttp3.Request; 19 | import okhttp3.Response; 20 | import okhttp3.logging.HttpLoggingInterceptor; 21 | import retrofit2.Retrofit; 22 | import retrofit2.converter.gson.GsonConverterFactory; 23 | 24 | 25 | public class RESTHelper { 26 | private static final String TAG = "RESTHelper"; 27 | 28 | /** 29 | * Returns a retrofit rest adaptor class. The adaptor is created in calling code. 30 | * 31 | * @return A new RestAdapter instance. 32 | */ 33 | public Retrofit getRetrofit(final Context context) { 34 | //This method catches outgoing REST calls and injects the Authorization and host headers before 35 | //sending to REST endpoint 36 | Interceptor interceptor = new Interceptor() { 37 | @Override 38 | public Response intercept(Chain chain) throws IOException { 39 | try { 40 | final String token = AuthenticationManager.getInstance(context).getAccessToken(); 41 | Request request = chain.request(); 42 | request = request.newBuilder() 43 | .addHeader("Authorization", "Bearer " + token) 44 | // This header has been added to identify this sample in the Microsoft Graph service. 45 | // If you're using this code for your project please remove the following line. 46 | .addHeader("SampleID", "android-java-connect-rest-sample") 47 | .build(); 48 | 49 | Response response = chain.proceed(request); 50 | return response; 51 | } catch (AuthenticatorException | IOException | UserNotAuthenticatedWrapperException | OperationCanceledException e) { 52 | Log.e(TAG, e.getMessage()); 53 | return null; 54 | } 55 | } 56 | }; 57 | 58 | return getRetrofit(interceptor); 59 | } 60 | 61 | public Retrofit getRetrofit(Interceptor interceptor) { 62 | HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); 63 | logging.setLevel(HttpLoggingInterceptor.Level.HEADERS); 64 | 65 | OkHttpClient client = new OkHttpClient.Builder() 66 | .addInterceptor(interceptor) 67 | .addInterceptor(logging) 68 | .build(); 69 | 70 | //Sets required properties in rest adaptor class before it is created. 71 | return new Retrofit.Builder() 72 | .baseUrl(Constants.MICROSOFT_GRAPH_API_ENDPOINT_RESOURCE_ID) 73 | .client(client) 74 | .addConverterFactory(GsonConverterFactory.create()) 75 | .build(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /oidclib/src/main/res/layout/activity_authentication.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 27 | 28 | 33 | 41 | 42 | 43 | 48 | 56 | 57 | 58 |