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

Commit a751d3e

Browse files
committed
Code cleanup and ReadMe content update
1 parent c794d6d commit a751d3e

File tree

6 files changed

+26
-20
lines changed

6 files changed

+26
-20
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ To use the Microsoft Graph SDK snippets project, you need the following:
118118
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.
119119
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`**
120120
<br/>For example: `msal0575d7fe-8ec7-4925-9ce2-87074778a039` is copied and `://auth` is ignored.
121-
4. Paste the clipboard contents in **app/src/main/AndroidManifest.xml**, line 42 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 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.
123123

124124
## Run the project
125125
After you've built the project you can run it on an emulator or device.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ dependencies {
5555
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
5656
androidTestImplementation 'com.android.support.test.espresso:espresso-intents:2.2.2'
5757
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'
58+
//implementation 'com.microsoft.graph:microsoft-graph:1.2.0'
59+
// implementation 'com.microsoft.identity.client:msal:0.2.2'
6060
implementation 'com.microsoft.graph:microsoft-graph-android-auth:0.1.0-SNAPSHOT'
6161
}

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@
3838
<action android:name="android.intent.action.VIEW" />
3939
<category android:name="android.intent.category.DEFAULT" />
4040
<category android:name="android.intent.category.BROWSABLE" />
41-
<data android:scheme="msalEnter_ClientId_Here"
42-
android:host="auth" />
41+
<data android:scheme="msalENTER_YOUR_CLIENT_ID" android:host="auth" />
4342
</intent-filter>
4443
</activity>
4544
<meta-data
4645
android:name="authority string"
4746
android:value="https://login.microsoftonline.com/common"/>
4847
<meta-data
4948
android:name="com.microsoft.identity.client.ClientId"
50-
android:value="Enter_ClientId_Here"/>
49+
android:value="ENTER_YOUR_CLIENT_ID"/>
5150
</application>
5251
</manifest>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public class AuthenticationManager implements IAuthenticationProvider {
3333
private static PublicClientApplication mPublicClientApplication;
3434
private AuthenticationResult mAuthResult;
3535
private MSALAuthenticationCallback mActivityCallback;
36-
public static MSALAuthenticationProvider msalAuthenticationProvider;
3736

3837
private AuthenticationManager() {
3938
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ 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", "Calendars.ReadWrite","Group.Read.All"};
13+
public static final String[] SCOPES = {"openid", "Mail.ReadWrite","Mail.Send","Files.ReadWrite",
14+
"User.Read.All", "Calendars.ReadWrite","Group.Read.All","Group.ReadWrite.All",};
1415
}

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public class SnippetApp extends Application {
1717
private static SnippetApp sSnippetApp;
1818
private static SignInActivity signInActivity;
1919
private AuthenticationManager mAuthenticationManager;
20+
private MSALAuthenticationProvider msalAuthenticationProvider;
21+
private IGraphServiceClient graphClient;
2022

2123
public static SnippetApp getApp() {
2224
return sSnippetApp;
@@ -33,17 +35,22 @@ public void onCreate() {
3335

3436
public IGraphServiceClient getGraphServiceClient() {
3537

36-
MSALAuthenticationProvider msalAuthenticationProvider = new MSALAuthenticationProvider(
37-
getAppActivity(),
38-
SnippetApp.getApp(),
39-
mAuthenticationManager.getPublicClient(),
40-
ServiceConstants.SCOPES);
41-
42-
IGraphServiceClient graphClient =
43-
GraphServiceClient
44-
.builder()
45-
.authenticationProvider(msalAuthenticationProvider)
46-
.buildClient();
38+
if(msalAuthenticationProvider == null) {
39+
msalAuthenticationProvider = new MSALAuthenticationProvider(
40+
getAppActivity(),
41+
SnippetApp.getApp(),
42+
mAuthenticationManager.getPublicClient(),
43+
ServiceConstants.SCOPES);
44+
}
45+
46+
if(graphClient == null) {
47+
graphClient =
48+
GraphServiceClient
49+
.builder()
50+
.authenticationProvider(msalAuthenticationProvider)
51+
.buildClient();
52+
}
53+
4754
return graphClient;
4855
}
4956

0 commit comments

Comments
 (0)