Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit b7a2724

Browse files
authored
Merge pull request #14 from titusgicheru/master
Andoid-SDK update to Java-SDK and Android wrapper for MSAL
2 parents c7a922e + a751d3e commit b7a2724

35 files changed

+251
-279
lines changed

README.md

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,23 @@ To use the Microsoft Graph SDK snippets project, you need the following:
8888

8989
## Azure client application registration
9090

91-
92-
1. Sign in to the [Application Registration portal](https://apps.dev.microsoft.com).
93-
3. Click on the blue **Add an app** button on the right side of the page.
94-
4. Give your application a name.
95-
4. _Un_-check **Let us help you get started** under the **Guided Setup** section
96-
4. Click the blue **Create** button to create the registration.
97-
5. Click the **Add Platform** button under the **Platforms** section and choose **Native Application**.
98-
8. Configure Permissions for your application - Under **Microsoft Graph Permissions** click the blue **Add** button adjacent to **Delegated Permissions**
99-
9. Add the following delegated permissions:
100-
* Sign in and read user profile
101-
* Have full access to all files user can access
102-
* Have full access to user calendars
103-
* Read and write access to user mail
104-
* Send mail as a user
105-
* Read user mail
106-
* Read and write directory data
107-
* Read all users' basic profiles
108-
* Read and write all groups
109-
13. Click **Save** in the bottom menu.
91+
1. Navigate to the [Azure portal - App registrations](https://go.microsoft.com/fwlink/?linkid=2083908) page.
92+
1. Select **New registration**.
93+
1. When the **Register an application page** appears, enter your application's registration information:
94+
- In the **Name** section, enter a meaningful application name that will be displayed to users of the app, for example `Android Java Snippets Sample`.
95+
- In the **Supported account types** section, select **Accounts in any organizational directory**.
96+
1. Select **Register** to create the application.
97+
1. On the app **Overview** page, find the **Application (client) ID** value and record it for later. You'll need it to configure the Visual Studio configuration file for this project.
98+
1. In the list of pages for the app, select **Manifest**, and:
99+
- In the manifest editor, set the ``allowPublicClient`` property to **true**
100+
- Select **Save** in the bar above the manifest editor.
101+
1. In the list of pages for the app, select **API permissions**
102+
- Click the **Add a permission** button and then,
103+
- Ensure that the **Microsoft APIs** tab is selected
104+
- In the *Commonly used Microsoft APIs* section, click on **Microsoft Graph**
105+
- In the **Delegated permissions** section, ensure that the right permissions are checked. Use the search box if necessary.
106+
- **User.Read**, **Mail.Send**, **Mail.ReadWrite**, **Files.ReadWrite**, **User.ReadBasic.All**, **Calendars.ReadWrite**, **Group.Read.All**
107+
- Select the **Add permissions** button
110108

111109
> **Note:**
112110
> In [Configure the project](#configure-the-project), you'll be asked to copy some strings that are generated by the application registration portal. Be sure to stay on application registration page while you configure the project. The strings that you copy from the application registration will be pasted into the source code of the project.
@@ -120,8 +118,8 @@ To use the Microsoft Graph SDK snippets project, you need the following:
120118
5. Respond to the dialog box ("Gradle Sync: Gradle settings for this project are not configured yet. Would you like the project to use the Gradle wrapper? ") by clicking the **OK** button to use the Gradle wrapper.
121119
4. In the application registration page that you just visited, copy the custom redirect URI (`msal{application id as GUID}`) to the clipboard. **Be sure you don't copy `://auth`**
122120
<br/>For example: `msal0575d7fe-8ec7-4925-9ce2-87074778a039` is copied and `://auth` is ignored.
123-
4. Paste the clipboard contents in **app/src/main/AndroidManifest.xml**, line 42 to replace `ENTER_YOUR_CLIENT_ID` with the clipboard contents.
124-
4. Copy the **GUID portion** of the custom redirect URI into **app/src/main/AndroidManifest.xml**, line 51 to replace `ENTER_YOUR_CLIENT_ID` with the clipboard contents.
121+
4. Paste the clipboard contents in **app/src/main/AndroidManifest.xml**, line 41 to replace `ENTER_YOUR_CLIENT_ID` with the clipboard contents.
122+
4. Copy the **GUID portion** of the custom redirect URI into **app/src/main/AndroidManifest.xml**, line 49 to replace `ENTER_YOUR_CLIENT_ID` with the clipboard contents.
125123

126124
## Run the project
127125
After you've built the project you can run it on an emulator or device.
@@ -188,4 +186,4 @@ General questions about Microsoft Graph development should be posted to [Stack O
188186
|1.0|Initial release|
189187
|1.5|- MSAL authentication library replaced ADAL authentication library <br/> - Microsoft Graph SDK version 1.5|
190188

191-
Copyright (c) 2015 Microsoft. All rights reserved.
189+
Copyright (c) 2019 Microsoft. All rights reserved.

app/build.gradle

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 25
5-
buildToolsVersion '27.0.3'
4+
compileSdkVersion 26
5+
buildToolsVersion '28.0.3'
66
defaultConfig {
77
applicationId "com.microsoft.graph.snippets"
88
minSdkVersion 21
9-
targetSdkVersion 25
9+
targetSdkVersion 26
1010
versionCode 2
1111
versionName '1.5'
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -15,7 +15,6 @@ android {
1515
includeCompileClasspath false
1616
}
1717
}
18-
1918
}
2019
buildTypes {
2120
release {
@@ -28,6 +27,7 @@ android {
2827
exclude 'META-INF/NOTICE.txt'
2928
exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
3029
exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
30+
exclude 'META-INF/jersey-module-version'
3131
}
3232
configurations {
3333
all {
@@ -39,16 +39,12 @@ android {
3939
}
4040

4141
dependencies {
42-
implementation('com.microsoft.identity.client:msal:0.1.+') {
43-
exclude group: 'com.android.support', module: 'appcompat-v7'
44-
}
4542
implementation 'com.android.volley:volley:1.0.0'
4643
implementation 'com.android.support:support-fragment:25.1.0'
4744
implementation 'com.android.support:appcompat-v7:25.1.0'
4845
// Butterknife
4946
implementation 'com.jakewharton:butterknife:8.4.0'
5047
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
51-
implementation 'com.microsoft.graph:msgraph-sdk-android:1.5.0'
5248
implementation 'joda-time:joda-time:2.9.4'
5349
implementation 'com.google.guava:guava:19.0'
5450
// Test libraries
@@ -59,4 +55,7 @@ dependencies {
5955
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
6056
androidTestImplementation 'com.android.support.test.espresso:espresso-intents:2.2.2'
6157
androidTestImplementation 'com.android.support.test.espresso:espresso-web:2.2.2'
58+
//implementation 'com.microsoft.graph:microsoft-graph:1.2.0'
59+
// implementation 'com.microsoft.identity.client:msal:0.2.2'
60+
implementation 'com.microsoft.graph:microsoft-graph-android-auth:0.1.0-SNAPSHOT'
6261
}

app/src/androidTest/java/com/microsoft/graph/snippets/SignInActivityTests.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@
1010
import android.support.test.espresso.web.webdriver.Locator;
1111
import android.support.test.rule.ActivityTestRule;
1212
import android.support.test.runner.AndroidJUnit4;
13-
1413
import junit.framework.AssertionFailedError;
15-
1614
import org.junit.After;
1715
import org.junit.Before;
1816
import org.junit.BeforeClass;
1917
import org.junit.Rule;
2018
import org.junit.Test;
2119
import org.junit.runner.RunWith;
22-
2320
import java.io.FileNotFoundException;
24-
2521
import static android.support.test.espresso.Espresso.onView;
2622
import static android.support.test.espresso.action.ViewActions.click;
2723
import static android.support.test.espresso.intent.Intents.intended;

app/src/androidTest/java/com/microsoft/graph/snippets/SnippetDetailActivityTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@
99
import android.support.test.espresso.intent.Intents;
1010
import android.support.test.rule.ActivityTestRule;
1111
import android.support.test.runner.AndroidJUnit4;
12-
1312
import org.junit.After;
1413
import org.junit.Before;
1514
import org.junit.BeforeClass;
1615
import org.junit.Rule;
1716
import org.junit.Test;
1817
import org.junit.runner.RunWith;
19-
2018
import java.io.FileNotFoundException;
2119
import java.util.List;
22-
2320
import static android.support.test.espresso.Espresso.onView;
2421
import static android.support.test.espresso.Espresso.registerIdlingResources;
2522
import static android.support.test.espresso.Espresso.unregisterIdlingResources;

app/src/androidTest/java/com/microsoft/graph/snippets/SnippetListActivityTests.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@
1010
import android.support.test.runner.AndroidJUnit4;
1111
import android.widget.ListAdapter;
1212
import android.widget.ListView;
13-
1413
import com.microsoft.graph.snippets.snippet.AbstractSnippet;
15-
1614
import org.junit.After;
1715
import org.junit.Assert;
1816
import org.junit.Before;
1917
import org.junit.Rule;
2018
import org.junit.Test;
2119
import org.junit.runner.RunWith;
22-
2320
import java.util.ArrayList;
2421
import java.util.List;
25-
2622
import static android.support.test.espresso.Espresso.onView;
2723
import static android.support.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
2824
import static android.support.test.espresso.action.ViewActions.click;

app/src/androidTest/java/com/microsoft/graph/snippets/TestCredentials.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
package com.microsoft.graph.snippets;
66

77
import android.os.Environment;
8-
98
import com.google.gson.JsonObject;
109
import com.google.gson.JsonParser;
11-
1210
import java.io.File;
1311
import java.io.FileNotFoundException;
1412
import java.io.FileReader;

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,13 @@
3232
<meta-data
3333
android:name="android.support.PARENT_ACTIVITY"
3434
android:value="com.microsoft.graph.snippets.SnippetListActivity" />
35-
3635
<activity
3736
android:name="com.microsoft.identity.client.BrowserTabActivity">
3837
<intent-filter>
3938
<action android:name="android.intent.action.VIEW" />
4039
<category android:name="android.intent.category.DEFAULT" />
4140
<category android:name="android.intent.category.BROWSABLE" />
42-
<data android:scheme="msalENTER_YOUR_CLIENT_ID"
43-
android:host="auth" />
41+
<data android:scheme="msalENTER_YOUR_CLIENT_ID" android:host="auth" />
4442
</intent-filter>
4543
</activity>
4644
<meta-data
@@ -49,7 +47,5 @@
4947
<meta-data
5048
android:name="com.microsoft.identity.client.ClientId"
5149
android:value="ENTER_YOUR_CLIENT_ID"/>
52-
5350
</application>
54-
5551
</manifest>

app/src/main/java/com/microsoft/graph/snippets/AuthenticationManager.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@
99
import android.app.Activity;
1010
import android.content.Context;
1111
import android.util.Log;
12-
1312
import com.microsoft.graph.authentication.IAuthenticationProvider;
13+
import com.microsoft.graph.authentication.MSALAuthenticationProvider;
1414
import com.microsoft.graph.http.IHttpRequest;
1515
import com.microsoft.graph.snippets.application.SnippetApp;
16+
import com.microsoft.graph.snippets.util.IManifestReader;
17+
import com.microsoft.graph.snippets.util.ManifestReader;
1618
import com.microsoft.identity.client.AuthenticationCallback;
1719
import com.microsoft.identity.client.AuthenticationResult;
18-
import com.microsoft.identity.client.MsalException;
20+
import com.microsoft.identity.client.IAccount;
1921
import com.microsoft.identity.client.PublicClientApplication;
20-
import com.microsoft.identity.client.User;
22+
import com.microsoft.identity.client.exception.MsalException;
23+
2124

2225
import java.io.IOException;
2326

@@ -30,14 +33,17 @@ public class AuthenticationManager implements IAuthenticationProvider {
3033
private static PublicClientApplication mPublicClientApplication;
3134
private AuthenticationResult mAuthResult;
3235
private MSALAuthenticationCallback mActivityCallback;
36+
3337
private AuthenticationManager() {
3438
}
3539

3640
public static synchronized AuthenticationManager getInstance() {
3741
if (INSTANCE == null) {
3842
INSTANCE = new AuthenticationManager();
3943
if (mPublicClientApplication == null) {
40-
mPublicClientApplication = new PublicClientApplication(SnippetApp.getApp());
44+
IManifestReader metaDataReader = new ManifestReader();
45+
String clientID = metaDataReader.getApplicationMetadataValueString("com.microsoft.identity.client.ClientId");
46+
mPublicClientApplication = new PublicClientApplication(SnippetApp.getContext(), clientID);
4147
}
4248
}
4349
return INSTANCE;
@@ -66,7 +72,7 @@ public PublicClientApplication getPublicClient(){
6672
* to null, and removing the user id from shred preferences.
6773
*/
6874
public void disconnect() {
69-
mPublicClientApplication.remove(mAuthResult.getUser());
75+
mPublicClientApplication.removeAccount(mAuthResult.getAccount());
7076
// Reset the AuthenticationManager object
7177
AuthenticationManager.resetInstance();
7278
}
@@ -82,7 +88,7 @@ public void callAcquireToken(Activity activity, final MSALAuthenticationCallback
8288
mPublicClientApplication.acquireToken(
8389
activity, ServiceConstants.SCOPES, getAuthInteractiveCallback());
8490
}
85-
public void callAcquireTokenSilent(User user, boolean forceRefresh, MSALAuthenticationCallback msalAuthenticationCallback) {
91+
public void callAcquireTokenSilent(IAccount user, boolean forceRefresh, MSALAuthenticationCallback msalAuthenticationCallback) {
8692
mActivityCallback = msalAuthenticationCallback;
8793
mPublicClientApplication.acquireTokenSilentAsync(ServiceConstants.SCOPES, user, null, forceRefresh, getAuthSilentCallback());
8894
}

app/src/main/java/com/microsoft/graph/snippets/BaseActivity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66

77
import android.app.Activity;
88

9-
109
public abstract class BaseActivity extends Activity {
1110
}

app/src/main/java/com/microsoft/graph/snippets/MSALAuthenticationCallback.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package com.microsoft.graph.snippets;
22

33
import com.microsoft.identity.client.AuthenticationResult;
4-
import com.microsoft.identity.client.MsalException;
5-
4+
import com.microsoft.identity.client.exception.MsalException;
65

76
interface MSALAuthenticationCallback {
87
void onSuccess(AuthenticationResult authenticationResult);

0 commit comments

Comments
 (0)