capacitor-auth-manager 2.4.1 → 2.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -1
- package/CapacitorAuthManager.podspec +9 -17
- package/README.md +505 -0
- package/android/build.gradle +6 -16
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/CapacitorAuthManager.java +1 -1
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/GoogleAuthProvider.java +2 -5
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/ProviderFactory.java +10 -110
- package/ios/Plugin/CapacitorAuthManager.swift +6 -15
- package/ios/Plugin/Plugin.swift +4 -2
- package/package.json +12 -24
- package/Readme.md +0 -203
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/FacebookAuthProvider.java +0 -389
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/MicrosoftAuthProvider.java +0 -455
- package/ios/Plugin/AppleAuthProvider.swift +0 -288
- package/ios/Plugin/FacebookAuthProvider.swift +0 -297
- package/ios/Plugin/GitHubAuthProvider.swift +0 -54
- package/ios/Plugin/LinkedInAuthProvider.swift +0 -63
- package/ios/Plugin/MicrosoftAuthProvider.swift +0 -315
- package/ios/Plugin/OAuthWebProvider.swift +0 -415
- package/ios/Plugin/SlackAuthProvider.swift +0 -108
package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/MicrosoftAuthProvider.java
DELETED
|
@@ -1,455 +0,0 @@
|
|
|
1
|
-
package com.aoneahsan.capacitor_auth_manager;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.content.Context;
|
|
5
|
-
|
|
6
|
-
import com.getcapacitor.JSObject;
|
|
7
|
-
import com.microsoft.identity.client.AcquireTokenParameters;
|
|
8
|
-
import com.microsoft.identity.client.AcquireTokenSilentParameters;
|
|
9
|
-
import com.microsoft.identity.client.AuthenticationCallback;
|
|
10
|
-
import com.microsoft.identity.client.IAccount;
|
|
11
|
-
import com.microsoft.identity.client.IAuthenticationResult;
|
|
12
|
-
import com.microsoft.identity.client.IPublicClientApplication;
|
|
13
|
-
import com.microsoft.identity.client.ISingleAccountPublicClientApplication;
|
|
14
|
-
import com.microsoft.identity.client.Prompt;
|
|
15
|
-
import com.microsoft.identity.client.PublicClientApplication;
|
|
16
|
-
import com.microsoft.identity.client.SilentAuthenticationCallback;
|
|
17
|
-
import com.microsoft.identity.client.exception.MsalClientException;
|
|
18
|
-
import com.microsoft.identity.client.exception.MsalException;
|
|
19
|
-
import com.microsoft.identity.client.exception.MsalServiceException;
|
|
20
|
-
import com.microsoft.identity.client.exception.MsalUiRequiredException;
|
|
21
|
-
|
|
22
|
-
import org.json.JSONArray;
|
|
23
|
-
|
|
24
|
-
import java.text.SimpleDateFormat;
|
|
25
|
-
import java.util.ArrayList;
|
|
26
|
-
import java.util.Arrays;
|
|
27
|
-
import java.util.Date;
|
|
28
|
-
import java.util.List;
|
|
29
|
-
import java.util.Locale;
|
|
30
|
-
import java.util.TimeZone;
|
|
31
|
-
|
|
32
|
-
public class MicrosoftAuthProvider implements BaseAuthProvider {
|
|
33
|
-
private static final String TAG = "MicrosoftAuthProvider";
|
|
34
|
-
|
|
35
|
-
private final Context context;
|
|
36
|
-
private final Activity activity;
|
|
37
|
-
private final AuthStorage storage;
|
|
38
|
-
private final AuthLogger logger;
|
|
39
|
-
|
|
40
|
-
private String clientId;
|
|
41
|
-
private String authority;
|
|
42
|
-
private String redirectUri;
|
|
43
|
-
private List<String> scopes;
|
|
44
|
-
private ISingleAccountPublicClientApplication msalApplication;
|
|
45
|
-
private JSObject currentUser;
|
|
46
|
-
private IAccount currentAccount;
|
|
47
|
-
|
|
48
|
-
public MicrosoftAuthProvider(Context context, Activity activity, AuthStorage storage, AuthLogger logger) {
|
|
49
|
-
this.context = context;
|
|
50
|
-
this.activity = activity;
|
|
51
|
-
this.storage = storage;
|
|
52
|
-
this.logger = logger;
|
|
53
|
-
this.scopes = new ArrayList<>(Arrays.asList("openid", "profile", "email"));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public void setClientId(String clientId) {
|
|
57
|
-
this.clientId = clientId;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public void setAuthority(String authority) {
|
|
61
|
-
this.authority = authority;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public void setRedirectUri(String redirectUri) {
|
|
65
|
-
this.redirectUri = redirectUri;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
public void setScopes(List<String> scopes) {
|
|
69
|
-
if (scopes != null && !scopes.isEmpty()) {
|
|
70
|
-
this.scopes = scopes;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
@Override
|
|
75
|
-
public void initialize(CapacitorAuthManager.AuthCallback<Void> callback) {
|
|
76
|
-
logger.info("Initializing Microsoft auth provider");
|
|
77
|
-
|
|
78
|
-
if (clientId == null || clientId.isEmpty()) {
|
|
79
|
-
callback.onResult(CapacitorAuthManager.AuthResult.error(
|
|
80
|
-
new Exception("Microsoft client ID is required")));
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
try {
|
|
85
|
-
// Build MSAL configuration JSON
|
|
86
|
-
String configJson = buildMsalConfig();
|
|
87
|
-
|
|
88
|
-
PublicClientApplication.createSingleAccountPublicClientApplication(
|
|
89
|
-
context,
|
|
90
|
-
configJson,
|
|
91
|
-
new IPublicClientApplication.ISingleAccountApplicationCreatedListener() {
|
|
92
|
-
@Override
|
|
93
|
-
public void onCreated(ISingleAccountPublicClientApplication application) {
|
|
94
|
-
msalApplication = application;
|
|
95
|
-
loadAccount(callback);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
@Override
|
|
99
|
-
public void onError(MsalException exception) {
|
|
100
|
-
logger.error("Failed to create MSAL application", exception);
|
|
101
|
-
callback.onResult(CapacitorAuthManager.AuthResult.error(exception));
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
);
|
|
105
|
-
} catch (Exception e) {
|
|
106
|
-
logger.error("Failed to initialize Microsoft auth", e);
|
|
107
|
-
callback.onResult(CapacitorAuthManager.AuthResult.error(e));
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private String buildMsalConfig() {
|
|
112
|
-
StringBuilder config = new StringBuilder();
|
|
113
|
-
config.append("{");
|
|
114
|
-
config.append("\"client_id\": \"").append(clientId).append("\",");
|
|
115
|
-
|
|
116
|
-
if (authority != null && !authority.isEmpty()) {
|
|
117
|
-
config.append("\"authorities\": [{");
|
|
118
|
-
config.append("\"type\": \"AAD\",");
|
|
119
|
-
config.append("\"authority_url\": \"").append(authority).append("\",");
|
|
120
|
-
config.append("\"default\": true");
|
|
121
|
-
config.append("}],");
|
|
122
|
-
} else {
|
|
123
|
-
config.append("\"authorities\": [{");
|
|
124
|
-
config.append("\"type\": \"AAD\",");
|
|
125
|
-
config.append("\"authority_url\": \"https://login.microsoftonline.com/common\",");
|
|
126
|
-
config.append("\"default\": true");
|
|
127
|
-
config.append("}],");
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (redirectUri != null && !redirectUri.isEmpty()) {
|
|
131
|
-
config.append("\"redirect_uri\": \"").append(redirectUri).append("\",");
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
config.append("\"account_mode\": \"SINGLE\"");
|
|
135
|
-
config.append("}");
|
|
136
|
-
|
|
137
|
-
return config.toString();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private void loadAccount(CapacitorAuthManager.AuthCallback<Void> callback) {
|
|
141
|
-
if (msalApplication == null) {
|
|
142
|
-
callback.onResult(CapacitorAuthManager.AuthResult.success(null));
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
msalApplication.getCurrentAccountAsync(new ISingleAccountPublicClientApplication.CurrentAccountCallback() {
|
|
147
|
-
@Override
|
|
148
|
-
public void onAccountLoaded(IAccount activeAccount) {
|
|
149
|
-
if (activeAccount != null) {
|
|
150
|
-
currentAccount = activeAccount;
|
|
151
|
-
currentUser = createUserObject(activeAccount);
|
|
152
|
-
logger.info("Restored previous Microsoft session");
|
|
153
|
-
}
|
|
154
|
-
callback.onResult(CapacitorAuthManager.AuthResult.success(null));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
@Override
|
|
158
|
-
public void onAccountChanged(IAccount priorAccount, IAccount currentAccount) {
|
|
159
|
-
if (currentAccount != null) {
|
|
160
|
-
MicrosoftAuthProvider.this.currentAccount = currentAccount;
|
|
161
|
-
MicrosoftAuthProvider.this.currentUser = createUserObject(currentAccount);
|
|
162
|
-
}
|
|
163
|
-
callback.onResult(CapacitorAuthManager.AuthResult.success(null));
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
@Override
|
|
167
|
-
public void onError(MsalException exception) {
|
|
168
|
-
logger.error("Failed to load Microsoft account", exception);
|
|
169
|
-
callback.onResult(CapacitorAuthManager.AuthResult.success(null));
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
@Override
|
|
175
|
-
public void signIn(JSObject credentials, JSObject options, CapacitorAuthManager.AuthCallback<JSObject> callback) {
|
|
176
|
-
logger.info("Starting Microsoft sign-in");
|
|
177
|
-
|
|
178
|
-
if (msalApplication == null) {
|
|
179
|
-
callback.onResult(CapacitorAuthManager.AuthResult.error(
|
|
180
|
-
new Exception("Microsoft Auth not initialized. Call initialize first.")));
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
String[] scopeArray = scopes.toArray(new String[0]);
|
|
185
|
-
|
|
186
|
-
AcquireTokenParameters parameters = new AcquireTokenParameters.Builder()
|
|
187
|
-
.startAuthorizationFromActivity(activity)
|
|
188
|
-
.withScopes(Arrays.asList(scopeArray))
|
|
189
|
-
.withPrompt(Prompt.SELECT_ACCOUNT)
|
|
190
|
-
.withCallback(new AuthenticationCallback() {
|
|
191
|
-
@Override
|
|
192
|
-
public void onCancel() {
|
|
193
|
-
logger.warn("Microsoft sign-in cancelled by user");
|
|
194
|
-
callback.onResult(CapacitorAuthManager.AuthResult.error(
|
|
195
|
-
new Exception("User cancelled sign-in")));
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
@Override
|
|
199
|
-
public void onSuccess(IAuthenticationResult authenticationResult) {
|
|
200
|
-
handleAuthResult(authenticationResult, callback);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
@Override
|
|
204
|
-
public void onError(MsalException exception) {
|
|
205
|
-
logger.error("Microsoft sign-in failed", exception);
|
|
206
|
-
callback.onResult(CapacitorAuthManager.AuthResult.error(exception));
|
|
207
|
-
}
|
|
208
|
-
})
|
|
209
|
-
.build();
|
|
210
|
-
|
|
211
|
-
msalApplication.acquireToken(parameters);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
private void handleAuthResult(IAuthenticationResult authResult, CapacitorAuthManager.AuthCallback<JSObject> callback) {
|
|
215
|
-
currentAccount = authResult.getAccount();
|
|
216
|
-
currentUser = createUserObject(currentAccount);
|
|
217
|
-
|
|
218
|
-
JSObject credential = createCredentialObject(authResult);
|
|
219
|
-
storage.saveCredential("microsoft", credential);
|
|
220
|
-
|
|
221
|
-
JSObject result = createAuthResultObject(authResult);
|
|
222
|
-
logger.info("Microsoft sign-in successful");
|
|
223
|
-
callback.onResult(CapacitorAuthManager.AuthResult.success(result));
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
@Override
|
|
227
|
-
public void signOut(JSObject options, CapacitorAuthManager.AuthCallback<Void> callback) {
|
|
228
|
-
logger.info("Signing out from Microsoft");
|
|
229
|
-
|
|
230
|
-
if (msalApplication == null) {
|
|
231
|
-
callback.onResult(CapacitorAuthManager.AuthResult.success(null));
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
msalApplication.signOut(new ISingleAccountPublicClientApplication.SignOutCallback() {
|
|
236
|
-
@Override
|
|
237
|
-
public void onSignOut() {
|
|
238
|
-
currentUser = null;
|
|
239
|
-
currentAccount = null;
|
|
240
|
-
storage.deleteCredential("microsoft");
|
|
241
|
-
callback.onResult(CapacitorAuthManager.AuthResult.success(null));
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
@Override
|
|
245
|
-
public void onError(MsalException exception) {
|
|
246
|
-
logger.error("Microsoft sign-out failed", exception);
|
|
247
|
-
callback.onResult(CapacitorAuthManager.AuthResult.error(exception));
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
@Override
|
|
253
|
-
public void getCurrentUser(CapacitorAuthManager.AuthCallback<JSObject> callback) {
|
|
254
|
-
if (currentUser != null) {
|
|
255
|
-
callback.onResult(CapacitorAuthManager.AuthResult.success(currentUser));
|
|
256
|
-
} else if (msalApplication != null) {
|
|
257
|
-
msalApplication.getCurrentAccountAsync(new ISingleAccountPublicClientApplication.CurrentAccountCallback() {
|
|
258
|
-
@Override
|
|
259
|
-
public void onAccountLoaded(IAccount activeAccount) {
|
|
260
|
-
if (activeAccount != null) {
|
|
261
|
-
currentAccount = activeAccount;
|
|
262
|
-
currentUser = createUserObject(activeAccount);
|
|
263
|
-
callback.onResult(CapacitorAuthManager.AuthResult.success(currentUser));
|
|
264
|
-
} else {
|
|
265
|
-
callback.onResult(CapacitorAuthManager.AuthResult.success(null));
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
@Override
|
|
270
|
-
public void onAccountChanged(IAccount priorAccount, IAccount currentAccount) {
|
|
271
|
-
if (currentAccount != null) {
|
|
272
|
-
MicrosoftAuthProvider.this.currentAccount = currentAccount;
|
|
273
|
-
MicrosoftAuthProvider.this.currentUser = createUserObject(currentAccount);
|
|
274
|
-
callback.onResult(CapacitorAuthManager.AuthResult.success(MicrosoftAuthProvider.this.currentUser));
|
|
275
|
-
} else {
|
|
276
|
-
callback.onResult(CapacitorAuthManager.AuthResult.success(null));
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
@Override
|
|
281
|
-
public void onError(MsalException exception) {
|
|
282
|
-
callback.onResult(CapacitorAuthManager.AuthResult.success(null));
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
} else {
|
|
286
|
-
callback.onResult(CapacitorAuthManager.AuthResult.success(null));
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
@Override
|
|
291
|
-
public void refreshToken(JSObject options, CapacitorAuthManager.AuthCallback<JSObject> callback) {
|
|
292
|
-
logger.info("Refreshing Microsoft token");
|
|
293
|
-
|
|
294
|
-
if (msalApplication == null || currentAccount == null) {
|
|
295
|
-
callback.onResult(CapacitorAuthManager.AuthResult.error(
|
|
296
|
-
new Exception("Microsoft Auth not initialized or no account")));
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
String[] scopeArray = scopes.toArray(new String[0]);
|
|
301
|
-
|
|
302
|
-
AcquireTokenSilentParameters parameters = new AcquireTokenSilentParameters.Builder()
|
|
303
|
-
.fromAuthority(currentAccount.getAuthority())
|
|
304
|
-
.withScopes(Arrays.asList(scopeArray))
|
|
305
|
-
.forAccount(currentAccount)
|
|
306
|
-
.forceRefresh(true)
|
|
307
|
-
.withCallback(new SilentAuthenticationCallback() {
|
|
308
|
-
@Override
|
|
309
|
-
public void onSuccess(IAuthenticationResult authenticationResult) {
|
|
310
|
-
JSObject credential = createCredentialObject(authenticationResult);
|
|
311
|
-
storage.saveCredential("microsoft", credential);
|
|
312
|
-
|
|
313
|
-
JSObject result = createAuthResultObject(authenticationResult);
|
|
314
|
-
result.put("operationType", "refresh");
|
|
315
|
-
callback.onResult(CapacitorAuthManager.AuthResult.success(result));
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
@Override
|
|
319
|
-
public void onError(MsalException exception) {
|
|
320
|
-
if (exception instanceof MsalUiRequiredException) {
|
|
321
|
-
// Need interactive sign-in
|
|
322
|
-
signIn(null, null, callback);
|
|
323
|
-
} else {
|
|
324
|
-
logger.error("Failed to refresh Microsoft token", exception);
|
|
325
|
-
callback.onResult(CapacitorAuthManager.AuthResult.error(exception));
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
})
|
|
329
|
-
.build();
|
|
330
|
-
|
|
331
|
-
msalApplication.acquireTokenSilentAsync(parameters);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
@Override
|
|
335
|
-
public void isSupported(CapacitorAuthManager.AuthCallback<Boolean> callback) {
|
|
336
|
-
callback.onResult(CapacitorAuthManager.AuthResult.success(true));
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
@Override
|
|
340
|
-
public void linkAccount(JSObject credentials, JSObject options, CapacitorAuthManager.AuthCallback<JSObject> callback) {
|
|
341
|
-
signIn(credentials, options, callback);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
@Override
|
|
345
|
-
public void unlinkAccount(CapacitorAuthManager.AuthCallback<Void> callback) {
|
|
346
|
-
signOut(null, callback);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
@Override
|
|
350
|
-
public void getIdToken(boolean forceRefresh, CapacitorAuthManager.AuthCallback<JSObject> callback) {
|
|
351
|
-
if (msalApplication == null || currentAccount == null) {
|
|
352
|
-
callback.onResult(CapacitorAuthManager.AuthResult.error(
|
|
353
|
-
new Exception("Microsoft Auth not initialized or no account")));
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
String[] scopeArray = scopes.toArray(new String[0]);
|
|
358
|
-
|
|
359
|
-
AcquireTokenSilentParameters parameters = new AcquireTokenSilentParameters.Builder()
|
|
360
|
-
.fromAuthority(currentAccount.getAuthority())
|
|
361
|
-
.withScopes(Arrays.asList(scopeArray))
|
|
362
|
-
.forAccount(currentAccount)
|
|
363
|
-
.forceRefresh(forceRefresh)
|
|
364
|
-
.withCallback(new SilentAuthenticationCallback() {
|
|
365
|
-
@Override
|
|
366
|
-
public void onSuccess(IAuthenticationResult authenticationResult) {
|
|
367
|
-
JSObject result = new JSObject();
|
|
368
|
-
result.put("token", authenticationResult.getAccessToken());
|
|
369
|
-
callback.onResult(CapacitorAuthManager.AuthResult.success(result));
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
@Override
|
|
373
|
-
public void onError(MsalException exception) {
|
|
374
|
-
callback.onResult(CapacitorAuthManager.AuthResult.error(exception));
|
|
375
|
-
}
|
|
376
|
-
})
|
|
377
|
-
.build();
|
|
378
|
-
|
|
379
|
-
msalApplication.acquireTokenSilentAsync(parameters);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
@Override
|
|
383
|
-
public void revokeAccess(String token, CapacitorAuthManager.AuthCallback<Void> callback) {
|
|
384
|
-
// Microsoft requires web-based sign out for full revocation
|
|
385
|
-
signOut(null, callback);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
private JSObject createUserObject(IAccount account) {
|
|
389
|
-
JSObject user = new JSObject();
|
|
390
|
-
user.put("uid", account.getId());
|
|
391
|
-
user.put("email", account.getUsername());
|
|
392
|
-
user.put("emailVerified", account.getUsername() != null && account.getUsername().contains("@"));
|
|
393
|
-
user.put("displayName", account.getUsername());
|
|
394
|
-
user.put("photoURL", null);
|
|
395
|
-
user.put("phoneNumber", null);
|
|
396
|
-
user.put("isAnonymous", false);
|
|
397
|
-
user.put("tenantId", account.getTenantId());
|
|
398
|
-
|
|
399
|
-
// Provider data
|
|
400
|
-
JSONArray providerData = new JSONArray();
|
|
401
|
-
JSObject provider = new JSObject();
|
|
402
|
-
provider.put("providerId", "microsoft.com");
|
|
403
|
-
provider.put("uid", account.getId());
|
|
404
|
-
provider.put("displayName", account.getUsername());
|
|
405
|
-
provider.put("email", account.getUsername());
|
|
406
|
-
provider.put("phoneNumber", null);
|
|
407
|
-
provider.put("photoURL", null);
|
|
408
|
-
providerData.put(provider);
|
|
409
|
-
user.put("providerData", providerData);
|
|
410
|
-
|
|
411
|
-
// Metadata
|
|
412
|
-
JSObject metadata = new JSObject();
|
|
413
|
-
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
|
|
414
|
-
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
|
415
|
-
metadata.put("lastSignInTime", sdf.format(new Date()));
|
|
416
|
-
user.put("metadata", metadata);
|
|
417
|
-
|
|
418
|
-
return user;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
private JSObject createCredentialObject(IAuthenticationResult authResult) {
|
|
422
|
-
JSObject credential = new JSObject();
|
|
423
|
-
credential.put("providerId", "microsoft.com");
|
|
424
|
-
credential.put("signInMethod", "oauth");
|
|
425
|
-
credential.put("accessToken", authResult.getAccessToken());
|
|
426
|
-
credential.put("idToken", authResult.getAccount().getIdToken());
|
|
427
|
-
credential.put("expiresAt", authResult.getExpiresOn().getTime());
|
|
428
|
-
credential.put("tokenType", "Bearer");
|
|
429
|
-
|
|
430
|
-
StringBuilder scopeStr = new StringBuilder();
|
|
431
|
-
for (String scope : authResult.getScope()) {
|
|
432
|
-
if (scopeStr.length() > 0) scopeStr.append(" ");
|
|
433
|
-
scopeStr.append(scope);
|
|
434
|
-
}
|
|
435
|
-
credential.put("scope", scopeStr.toString());
|
|
436
|
-
|
|
437
|
-
return credential;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
private JSObject createAuthResultObject(IAuthenticationResult authResult) {
|
|
441
|
-
JSObject result = new JSObject();
|
|
442
|
-
result.put("user", createUserObject(authResult.getAccount()));
|
|
443
|
-
result.put("credential", createCredentialObject(authResult));
|
|
444
|
-
|
|
445
|
-
JSObject additionalUserInfo = new JSObject();
|
|
446
|
-
additionalUserInfo.put("isNewUser", false);
|
|
447
|
-
additionalUserInfo.put("providerId", "microsoft.com");
|
|
448
|
-
additionalUserInfo.put("username", authResult.getAccount().getUsername());
|
|
449
|
-
result.put("additionalUserInfo", additionalUserInfo);
|
|
450
|
-
|
|
451
|
-
result.put("operationType", "signIn");
|
|
452
|
-
|
|
453
|
-
return result;
|
|
454
|
-
}
|
|
455
|
-
}
|