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

Commit efb8407

Browse files
committed
Update from Android-SDK to Java-SDK
1 parent c7a922e commit efb8407

23 files changed

+256
-212
lines changed

README.md

Lines changed: 18 additions & 20 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.
@@ -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: 6 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,6 @@ 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'
6260
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212

1313
import com.microsoft.graph.authentication.IAuthenticationProvider;
1414
import com.microsoft.graph.http.IHttpRequest;
15+
import com.microsoft.graph.models.extensions.User;
1516
import com.microsoft.graph.snippets.application.SnippetApp;
1617
import com.microsoft.identity.client.AuthenticationCallback;
1718
import com.microsoft.identity.client.AuthenticationResult;
18-
import com.microsoft.identity.client.MsalException;
19+
//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.User;
23+
import com.microsoft.identity.client.exception.MsalException;
2124

2225
import java.io.IOException;
2326

@@ -66,7 +69,7 @@ public PublicClientApplication getPublicClient(){
6669
* to null, and removing the user id from shred preferences.
6770
*/
6871
public void disconnect() {
69-
mPublicClientApplication.remove(mAuthResult.getUser());
72+
mPublicClientApplication.removeAccount(mAuthResult.getAccount());
7073
// Reset the AuthenticationManager object
7174
AuthenticationManager.resetInstance();
7275
}
@@ -82,7 +85,7 @@ public void callAcquireToken(Activity activity, final MSALAuthenticationCallback
8285
mPublicClientApplication.acquireToken(
8386
activity, ServiceConstants.SCOPES, getAuthInteractiveCallback());
8487
}
85-
public void callAcquireTokenSilent(User user, boolean forceRefresh, MSALAuthenticationCallback msalAuthenticationCallback) {
88+
public void callAcquireTokenSilent(IAccount user, boolean forceRefresh, MSALAuthenticationCallback msalAuthenticationCallback) {
8689
mActivityCallback = msalAuthenticationCallback;
8790
mPublicClientApplication.acquireTokenSilentAsync(ServiceConstants.SCOPES, user, null, forceRefresh, getAuthSilentCallback());
8891
}

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

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

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

67

78
interface MSALAuthenticationCallback {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ public class ServiceConstants {
1010
// The Microsoft Graph delegated permissions that you set in the application
1111
// registration portal must match these scope values.
1212
// Update this constant with the scope (permission) values for your application:
13-
public static final String[] SCOPES = {"openid", "Mail.ReadWrite","mail.send","Files.ReadWrite","User.ReadBasic.All"};
13+
public static final String[] SCOPES = {"openid", "Mail.ReadWrite","Mail.Send","Files.ReadWrite","User.ReadBasic.All", "Calendars.ReadWrite","Group.Read.All"};
1414
}

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,22 @@
1111
import android.widget.TextView;
1212
import android.widget.Toast;
1313

14+
import com.microsoft.graph.models.extensions.User;
1415
import com.microsoft.graph.snippets.util.IManifestReader;
1516
import com.microsoft.graph.snippets.util.ManifestReader;
1617
import com.microsoft.graph.snippets.util.SharedPrefsUtil;
1718
import com.microsoft.identity.client.AuthenticationResult;
19+
import com.microsoft.identity.client.IAccount;
1820
import com.microsoft.identity.client.Logger;
19-
import com.microsoft.identity.client.MsalClientException;
20-
import com.microsoft.identity.client.MsalException;
21-
import com.microsoft.identity.client.MsalServiceException;
22-
import com.microsoft.identity.client.MsalUiRequiredException;
23-
import com.microsoft.identity.client.User;
21+
import com.microsoft.identity.client.exception.MsalClientException;
22+
import com.microsoft.identity.client.exception.MsalException;
23+
import com.microsoft.identity.client.exception.MsalServiceException;
24+
import com.microsoft.identity.client.exception.MsalUiRequiredException;
25+
//import com.microsoft.identity.client.MsalClientException;
26+
//import com.microsoft.identity.client.MsalException;
27+
//import com.microsoft.identity.client.MsalServiceException;
28+
//import com.microsoft.identity.client.MsalUiRequiredException;
29+
//import com.microsoft.identity.client.User;
2430

2531
import java.net.URI;
2632
import java.util.List;
@@ -84,8 +90,8 @@ public void onSuccess(AuthenticationResult authenticationResult) {
8490
// get the user display name
8591
final String userDisplayableId =
8692
authenticationResult
87-
.getUser()
88-
.getDisplayableId();
93+
.getAccount()
94+
.getUsername();
8995

9096
// get the index of their '@' in the name (to determine domain)
9197
final int at = userDisplayableId.indexOf("@");
@@ -164,10 +170,10 @@ private void connect() {
164170
/* Attempt to get a user and acquireTokenSilent
165171
* If this fails we do an interactive request
166172
*/
167-
List<User> users = null;
173+
List<IAccount> users = null;
168174

169175
try {
170-
users = mgr.getPublicClient().getUsers();
176+
users = mgr.getPublicClient().getAccounts();
171177

172178
if (users != null && users.size() == 1) {
173179
/* We have 1 user */
@@ -184,12 +190,15 @@ private void connect() {
184190
this,
185191
this);
186192
}
187-
} catch (MsalClientException e) {
188-
Log.d(TAG, "MSAL Exception Generated while getting users: " + e.toString());
189-
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
190-
193+
}
191194

192-
} catch (IndexOutOfBoundsException e) {
195+
// catch (MsalClientException e) {
196+
// Log.d(TAG, "MSAL Exception Generated while getting users: " + e.toString());
197+
// Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
198+
//
199+
//
200+
// }
201+
catch (IndexOutOfBoundsException e) {
193202
Log.d(TAG, "User at this position does not exist: " + e.toString());
194203
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
195204

@@ -215,7 +224,7 @@ private void start() {
215224
startActivity(appLaunch);
216225
}
217226

218-
public User mUser;
227+
public IAccount mUser;
219228

220229
@Override
221230
public void onError(Exception exception) {

app/src/main/java/com/microsoft/graph/snippets/application/SnippetApp.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99

1010
import com.microsoft.graph.core.DefaultClientConfig;
1111
import com.microsoft.graph.core.IClientConfig;
12-
import com.microsoft.graph.extensions.GraphServiceClient;
13-
import com.microsoft.graph.extensions.IGraphServiceClient;
12+
13+
//import com.microsoft.graph.extensions.GraphServiceClient;
14+
//import com.microsoft.graph.extensions.IGraphServiceClient;
15+
16+
import com.microsoft.graph.requests.extensions.GraphServiceClient;
17+
import com.microsoft.graph.models.extensions.IGraphServiceClient;
1418
import com.microsoft.graph.snippets.AuthenticationManager;
1519

1620

@@ -33,7 +37,7 @@ public IGraphServiceClient getGraphServiceClient() {
3337
IClientConfig clientConfig = DefaultClientConfig.createWithAuthenticationProvider(
3438
mAuthenticationManager
3539
);
36-
return new GraphServiceClient.Builder().fromConfig(clientConfig).buildClient();
40+
return GraphServiceClient.fromConfig(clientConfig);
3741
}
3842

3943
public static Context getContext() {

app/src/main/java/com/microsoft/graph/snippets/snippet/AbstractSnippet.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
package com.microsoft.graph.snippets.snippet;
66

77
import com.microsoft.graph.concurrency.ICallback;
8-
import com.microsoft.graph.extensions.IGraphServiceClient;
8+
//import com.microsoft.graph.extensions.IGraphServiceClient;
9+
import com.microsoft.graph.models.extensions.IGraphServiceClient;
910
import com.microsoft.graph.snippets.application.SnippetApp;
1011

1112
public abstract class AbstractSnippet<Result> {

0 commit comments

Comments
 (0)