|
6 | 6 |
|
7 | 7 | import android.accounts.AuthenticatorException; |
8 | 8 | import android.accounts.OperationCanceledException; |
| 9 | +import android.app.Activity; |
| 10 | +import android.app.Application; |
9 | 11 | import android.util.Log; |
10 | 12 |
|
11 | 13 | 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; |
14 | 15 | import com.microsoft.graph.requests.extensions.GraphServiceClient; |
15 | 16 | import com.microsoft.graph.models.extensions.IGraphServiceClient; |
16 | 17 | import com.microsoft.graph.http.IHttpRequest; |
|
21 | 22 | * Singleton class that manages a GraphServiceClient object. |
22 | 23 | * It implements IAuthentication provider to authenticate requests using an access token. |
23 | 24 | */ |
24 | | -public class GraphServiceClientManager implements IAuthenticationProvider { |
| 25 | +public class GraphServiceClientManager extends Application implements IAuthenticationProvider { |
25 | 26 | private IGraphServiceClient mGraphServiceClient; |
26 | 27 | private static GraphServiceClientManager INSTANCE; |
| 28 | + private AuthenticationManager mAuthenticationManager; |
| 29 | + private static Activity connectActivity; |
27 | 30 |
|
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 | + } |
29 | 39 |
|
30 | 40 | /** |
31 | 41 | * Appends an access token obtained from the {@link AuthenticationManager} class to the |
@@ -67,10 +77,18 @@ public synchronized IGraphServiceClient getGraphServiceClient() { |
67 | 77 |
|
68 | 78 | public synchronized IGraphServiceClient getGraphServiceClient(IAuthenticationProvider authenticationProvider) { |
69 | 79 | 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; |
74 | 92 | } |
75 | 93 | return mGraphServiceClient; |
76 | 94 | } |
|
0 commit comments