-
Notifications
You must be signed in to change notification settings - Fork 124
/
ISingleAccountPublicClientApplication.java
305 lines (283 loc) · 17.6 KB
/
ISingleAccountPublicClientApplication.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package com.microsoft.identity.client;
import android.app.Activity;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import com.microsoft.identity.client.exception.MsalException;
/**
* An interface that contains list of operations that are available when MSAL is in 'single account' mode.
* - In this mode, one account can be signed-in to the app.
* - If the user wants to acquire a token for another account, the previous account must be signed out first.
* <p>
* When the device is registered as 'shared', this will be the only available PublicClientApplication the app can obtain.
* The calling app has to support ISingleAccountPublicClientApplication if it is planning to support shared device mode.
* <p>
* In the shared device mode,
* - 'Sign-in' means that the user will be signed in to the device - not just this app.
* - Once an account is 'signed-in', every MSAL app on the device that support shared device mode will be able to retrieve this account, and use them to silently perform API calls.
* - 'Sign-out' means that user will be signed out from the device - every MSAL apps and the default browser.
*/
public interface ISingleAccountPublicClientApplication extends IPublicClientApplication {
/**
* Gets the current account and notify if the current account changes.
* This method must be called whenever the application is resumed or prior to running a scheduled background operation.
*
* @param callback a callback to be invoked when the operation finishes.
*/
void getCurrentAccountAsync(final CurrentAccountCallback callback);
/**
* Gets the current account and notify if the current account changes.
* This method must be called whenever the application is resumed or prior to running a scheduled background operation.
*
* @return CurrentAccountResult
*/
@WorkerThread
ICurrentAccountResult getCurrentAccount() throws InterruptedException, MsalException;
/**
* Allows a user to sign in to your application with one of their accounts. This method may only
* be called once: once a user is signed in, they must first be signed out before another user
* may sign in. If you wish to prompt the existing user for credentials use
* {@link #signInAgain(SignInParameters)} or
* {@link #acquireToken(AcquireTokenParameters)}.
* <p>
* Note: The authority used to make the sign in request will be either the MSAL default: https://login.microsoftonline.com/common
* or the default authority specified by you in your configuration.
*
* @param signInParameters the {@link SignInParameters} containing the needed fields for signIn flow. Activity, scopes, and callback must be non-null. loginHint and prompt are nullable
*/
void signIn(@NonNull final SignInParameters signInParameters);
/**
* @deprecated This method is now deprecated. The library is moving towards standardizing the use of {@link SignInParameters} as the
* parameters for the SingleAccountPublicClientApplication API.
* Use {@link ISingleAccountPublicClientApplication#signIn(SignInParameters)} instead.
*
* Allows a user to sign in to your application with one of their accounts. This method may only
* be called once: once a user is signed in, they must first be signed out before another user
* may sign in. If you wish to prompt the existing user for credentials use
* {@link #signInAgain(SignInParameters)} or
* {@link #acquireToken(AcquireTokenParameters)}.
* <p>
* Note: The authority used to make the sign in request will be either the MSAL default: https://login.microsoftonline.com/common
* or the default authority specified by you in your configuration.
*
* @param activity Non-null {@link Activity} that is used as the parent activity for launching the {@link com.microsoft.identity.common.internal.providers.oauth2.AuthorizationActivity}.
* @param loginHint Optional. If provided, will be used as the query parameter sent for authenticating the user,
* which will have the UPN pre-populated.
* @param scopes The non-null array of scopes to be consented to during sign in.
* MSAL always sends the scopes 'openid profile offline_access'. Do not include any of these scopes in the scope parameter.
* The access token returned is for MS Graph and will allow you to query for additional information about the signed in account.
* @param callback {@link AuthenticationCallback} that is used to send the result back. The success result will be
* sent back via {@link AuthenticationCallback#onSuccess(IAuthenticationResult)}.
* Failure case will be sent back via {
* @link AuthenticationCallback#onError(MsalException)}.
*/
@Deprecated
void signIn(@NonNull final Activity activity,
@Nullable final String loginHint,
@NonNull final String[] scopes,
@NonNull final AuthenticationCallback callback
);
/**
* @deprecated This method is now deprecated. The library is moving towards standardizing the use of {@link SignInParameters} as the
* parameters for the SingleAccountPublicClientApplication API.
* Use {@link ISingleAccountPublicClientApplication#signIn(SignInParameters)} instead.
*
* Allows a user to sign in to your application with one of their accounts. This method may only
* be called once: once a user is signed in, they must first be signed out before another user
* may sign in. If you wish to prompt the existing user for credentials use
* {@link #signInAgain(SignInParameters)} or
* {@link #acquireToken(AcquireTokenParameters)}.
* <p>
* Note: The authority used to make the sign in request will be either the MSAL default: https://login.microsoftonline.com/common
* or the default authority specified by you in your configuration
*
* @param activity Non-null {@link Activity} that is used as the parent activity for launching the {@link com.microsoft.identity.common.internal.providers.oauth2.AuthorizationActivity}.
* @param loginHint Optional. If provided, will be used as the query parameter sent for authenticating the user,
* which will have the UPN pre-populated.
* @param scopes The non-null array of scopes to be consented to during sign in.
* MSAL always sends the scopes 'openid profile offline_access'. Do not include any of these scopes in the scope parameter.
* The access token returned is for MS Graph and will allow you to query for additional information about the signed in account.
* @param callback {@link AuthenticationCallback} that is used to send the result back. The success result will be
* sent back via {@link AuthenticationCallback#onSuccess(IAuthenticationResult)}.
* Failure case will be sent back via {
* @link AuthenticationCallback#onError(MsalException)}.
*/
@Deprecated
void signIn(@NonNull final Activity activity,
@Nullable final String loginHint,
@NonNull final String[] scopes,
@Nullable final Prompt prompt,
@NonNull final AuthenticationCallback callback
);
/**
* Reauthorizes the current account according to the supplied scopes and prompt behavior.
* <p>
* Note: The authority used to make the sign in request will be either the MSAL default:
* https://login.microsoftonline.com/common or the default authority specified by you in your
* configuration. This flow requires activity, scopes, and callback. Prompt is optional.
*
* @param signInParameters the {@link SignInParameters} containing the needed fields for signIn flow. Activity, scopes, and callback must be non-null.
*/
void signInAgain(@NonNull final SignInParameters signInParameters);
/**
* @deprecated This method is now deprecated. The library is moving towards standardizing the use of {@link SignInParameters} as the
* parameters for the SingleAccountPublicClientApplication API.
* Use {@link ISingleAccountPublicClientApplication#signInAgain(SignInParameters)} instead.
*
* Reauthorizes the current account according to the supplied scopes and prompt behavior.
* <p>
* Note: The authority used to make the sign in request will be either the MSAL default:
* https://login.microsoftonline.com/common or the default authority specified by you in your
* configuration. This flow requires activity, scopes, and callback. Prompt is optional.
*
* @param activity Non-null {@link Activity} that is used as the parent activity for
* launching the {@link com.microsoft.identity.common.internal.providers.oauth2.AuthorizationActivity}.
* @param scopes The non-null array of scopes to be consented to during sign in.
* MSAL always sends the scopes 'openid profile offline_access'. Do
* not include any of these scopes in the scope parameter. The access
* token returned is for MS Graph and will allow you to query for
* additional information about the signed in account.
* @param prompt Nullable. Indicates the type of user interaction that is required.
* If no argument is supplied the default behavior will be used.
* @param callback {@link AuthenticationCallback} that is used to send the result back.
* The success result will be sent back via
* {@link AuthenticationCallback#onSuccess(IAuthenticationResult)}.
* Failure case will be sent back via {@link AuthenticationCallback#onError(MsalException)}.
*/
@Deprecated
void signInAgain(@NonNull final Activity activity,
@NonNull final String[] scopes,
@Nullable final Prompt prompt,
@NonNull final AuthenticationCallback callback
);
/**
* Signs out the current the Account and Credentials (tokens).
* NOTE: If a device is marked as a shared device within broker signout will be device wide.
*
* @param callback a callback to be invoked when the operation finishes.
*/
void signOut(@NonNull final SignOutCallback callback);
/**
* Signs out the current the Account and Credentials (tokens).
* NOTE: If a device is marked as a shared device within broker signout will be device wide.
*
* @return boolean indicating whether the account was removed successfully
*/
@WorkerThread
boolean signOut() throws MsalException, InterruptedException;
/**
* Perform acquire token silent call. If there is a valid access token in the cache, the sdk will return the access token; If
* no valid access token exists, the sdk will try to find a refresh token and use the refresh token to get a new access token. If refresh token does not exist
* or it fails the refresh, exception will be sent back via callback.
*
* @param acquireTokenSilentParameters the {@link AcquireTokenSilentParameters} containing the needed fields for acquireTokenSilent flow. Scopes, authority, and callback must be non-null.
*/
void acquireTokenSilentAsync(@NonNull final AcquireTokenSilentParameters acquireTokenSilentParameters);
/**
* @deprecated This method is now deprecated. The library is moving towards standardizing the use of {@link SignInParameters} as the
* parameters for the SingleAccountPublicClientApplication API.
* Use {@link ISingleAccountPublicClientApplication#acquireTokenSilentAsync(AcquireTokenSilentParameters)} instead.
*
* Perform acquire token silent call. If there is a valid access token in the cache, the sdk will return the access token; If
* no valid access token exists, the sdk will try to find a refresh token and use the refresh token to get a new access token. If refresh token does not exist
* or it fails the refresh, exception will be sent back via callback.
*
* @param scopes The non-null array of scopes to be requested for the access token.
* MSAL always sends the scopes 'openid profile offline_access'. Do not include any of these scopes in the scope parameter.
* @param authority Authority to issue the token.
* @param callback {@link SilentAuthenticationCallback} that is used to send the result back. The success result will be
* sent back via {@link SilentAuthenticationCallback#onSuccess(IAuthenticationResult)}.
* Failure case will be sent back via {
* @link AuthenticationCallback#onError(MsalException)}.
*/
@Deprecated
void acquireTokenSilentAsync(@NonNull final String[] scopes,
@NonNull final String authority,
@NonNull final SilentAuthenticationCallback callback
);
/**
* Perform acquire token silent call. If there is a valid access token in the cache, the sdk will return the access token; If
* no valid access token exists, the sdk will try to find a refresh token and use the refresh token to get a new access token. If refresh token does not exist
* or it fails the refresh, exception will be sent back via callback.
*
* @param acquireTokenSilentParameters the {@link AcquireTokenSilentParameters} containing the needed parameters for acquireTokenSilent flow. Scopes and authority must be non-null.
*/
@WorkerThread
IAuthenticationResult acquireTokenSilent(@NonNull final AcquireTokenSilentParameters acquireTokenSilentParameters) throws InterruptedException, MsalException;
/**
* @deprecated This method is now deprecated. The library is moving towards standardizing the use of {@link SignInParameters} as the
* parameters for the SingleAccountPublicClientApplication API.
* Use {@link ISingleAccountPublicClientApplication#acquireTokenSilent(AcquireTokenSilentParameters)} instead.
*
* Perform acquire token silent call. If there is a valid access token in the cache, the sdk will return the access token; If
* no valid access token exists, the sdk will try to find a refresh token and use the refresh token to get a new access token. If refresh token does not exist
* or it fails the refresh, exception will be sent back via callback.
*
* @param scopes The non-null array of scopes to be requested for the access token.
* MSAL always sends the scopes 'openid profile offline_access'. Do not include any of these scopes in the scope parameter.
* @param authority Authority to issue the token.
*/
@WorkerThread
@Deprecated
IAuthenticationResult acquireTokenSilent(@NonNull final String[] scopes,
@NonNull final String authority) throws MsalException, InterruptedException;
/**
* Callback for asynchronous loading of the msal IAccount account.
*/
interface CurrentAccountCallback {
/**
* Invoked when the account is loaded.
*
* @param activeAccount the signed-in account. This could be null.
*/
void onAccountLoaded(@Nullable final IAccount activeAccount);
/**
* Invoked when signed-in account is changed after the application resumes, or prior to running a scheduled background operation.
* The calling app is responsible for keeping track of this account and cleaning its states if the account changes.
*
* @param priorAccount the previous signed-in account. This could be null.
* @param currentAccount the current signed-in account. This could be null.
*/
void onAccountChanged(@Nullable final IAccount priorAccount, @Nullable final IAccount currentAccount);
/**
* Invoked when the account failed to load.
*
* @param exception the exception object.
*/
void onError(@NonNull final MsalException exception);
}
interface SignOutCallback {
/**
* Invoked when account successfully signed out
*/
void onSignOut();
/**
* Invoked when the account failed to load.
*
* @param exception the exception object.
*/
void onError(@NonNull final MsalException exception);
}
}