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

Commit 121d54b

Browse files
author
Irvine Sunday
committed
Refactored to use the Android wrapper
1 parent 3613000 commit 121d54b

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

app/src/main/java/com/microsoft/graph/connect/GraphServiceClientManager.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
import android.accounts.AuthenticatorException;
88
import android.accounts.OperationCanceledException;
9+
import android.app.Activity;
10+
import android.app.Application;
911
import android.util.Log;
1012

1113
import com.microsoft.graph.authentication.IAuthenticationProvider;
12-
import com.microsoft.graph.core.DefaultClientConfig;
13-
import com.microsoft.graph.core.IClientConfig;
14+
import com.microsoft.graph.authentication.MSALAuthenticationProvider;
1415
import com.microsoft.graph.requests.extensions.GraphServiceClient;
1516
import com.microsoft.graph.models.extensions.IGraphServiceClient;
1617
import com.microsoft.graph.http.IHttpRequest;
@@ -21,11 +22,20 @@
2122
* Singleton class that manages a GraphServiceClient object.
2223
* It implements IAuthentication provider to authenticate requests using an access token.
2324
*/
24-
public class GraphServiceClientManager implements IAuthenticationProvider {
25+
public class GraphServiceClientManager extends Application implements IAuthenticationProvider {
2526
private IGraphServiceClient mGraphServiceClient;
2627
private static GraphServiceClientManager INSTANCE;
28+
private AuthenticationManager mAuthenticationManager;
29+
private static Activity connectActivity;
2730

28-
private GraphServiceClientManager() {}
31+
public static GraphServiceClientManager getApp() {
32+
return INSTANCE;
33+
}
34+
public static Activity getAppActivity() {return connectActivity;}
35+
36+
private GraphServiceClientManager() {
37+
mAuthenticationManager = AuthenticationManager.getInstance();
38+
}
2939

3040
/**
3141
* Appends an access token obtained from the {@link AuthenticationManager} class to the
@@ -67,10 +77,18 @@ public synchronized IGraphServiceClient getGraphServiceClient() {
6777

6878
public synchronized IGraphServiceClient getGraphServiceClient(IAuthenticationProvider authenticationProvider) {
6979
if (mGraphServiceClient == null) {
70-
IClientConfig clientConfig = DefaultClientConfig.createWithAuthenticationProvider(
71-
authenticationProvider
72-
);
73-
mGraphServiceClient = GraphServiceClient.fromConfig(clientConfig);
80+
MSALAuthenticationProvider msalAuthenticationProvider = new MSALAuthenticationProvider(
81+
getAppActivity(),
82+
GraphServiceClientManager.getApp(),
83+
mAuthenticationManager.getPublicClient(),
84+
Constants.SCOPES);
85+
86+
IGraphServiceClient graphClient =
87+
GraphServiceClient
88+
.builder()
89+
.authenticationProvider(msalAuthenticationProvider)
90+
.buildClient();
91+
return graphClient;
7492
}
7593
return mGraphServiceClient;
7694
}

0 commit comments

Comments
 (0)