List of usage examples for com.facebook.react.bridge ReadableMap getBoolean
boolean getBoolean(@NonNull String name);
From source file:com.integrationtests.AWSRNTestExecutor.java
License:Open Source License
@ReactMethod public void testUpdateStatus(final ReadableMap options) throws RuntimeException { testCompleted = true;//from w w w.j av a 2 s . c om if (options.getBoolean("isFailed")) { testFailed = true; throw new RuntimeException("Test failed: " + options.toString()); } }
From source file:com.microsoft.aad.adal.ReactNativeAdalPlugin.java
License:Open Source License
@ReactMethod public void createAsync(ReadableMap obj, Callback callback) { try {/*from w w w. j ava 2s . co m*/ String authority = obj.hasKey("authority") ? obj.getString("authority") : null; boolean validateAuthority = obj.hasKey("validateAuthority") ? obj.getBoolean("validateAuthority") : false; getOrCreateContext(authority, validateAuthority); callback.invoke(); } catch (Exception e) { callback.invoke(e.getMessage()); } }
From source file:com.microsoft.aad.adal.ReactNativeAdalPlugin.java
License:Open Source License
@ReactMethod public void acquireTokenAsync(ReadableMap obj, Callback callback) { final AuthenticationContext authContext; String authority = obj.hasKey("authority") ? obj.getString("authority") : null; boolean validateAuthority = obj.hasKey("validateAuthority") ? obj.getBoolean("validateAuthority") : false; String resourceId = obj.hasKey("resourceId") ? obj.getString("resourceId") : null; String clientId = obj.hasKey("clientId") ? obj.getString("clientId") : null; String redirectUri = obj.hasKey("redirectUri") ? obj.getString("redirectUri") : null; String userId = obj.hasKey("userId") ? obj.getString("userId") : null; String extraQueryParams = obj.hasKey("extraQueryParams") ? obj.getString("extraQueryParams") : null; try {// w w w. jav a2 s . c om authContext = getOrCreateContext(authority, validateAuthority); } catch (Exception e) { callback.invoke(e.getMessage()); return; } if (userId != null) { ITokenCacheStore cache = authContext.getCache(); if (cache instanceof ITokenStoreQuery) { List<TokenCacheItem> tokensForUserId = ((ITokenStoreQuery) cache).getTokensForUser(userId); if (tokensForUserId.size() > 0) { // Try to acquire alias for specified userId userId = tokensForUserId.get(0).getUserInfo().getDisplayableId(); } } } authContext.acquireToken(this.getCurrentActivity(), resourceId, clientId, redirectUri, userId, SHOW_PROMPT_ALWAYS, extraQueryParams, new DefaultAuthenticationCallback(callback)); }
From source file:com.microsoft.aad.adal.ReactNativeAdalPlugin.java
License:Open Source License
@ReactMethod public void acquireTokenSilentAsync(ReadableMap obj, Callback callback) { //String authority, boolean validateAuthority, String resourceUrl, String clientId, String userId) { final AuthenticationContext authContext; String authority = obj.hasKey("authority") ? obj.getString("authority") : null; boolean validateAuthority = obj.hasKey("validateAuthority") ? obj.getBoolean("validateAuthority") : false; String resourceId = obj.hasKey("resourceId") ? obj.getString("resourceId") : null; String clientId = obj.hasKey("clientId") ? obj.getString("clientId") : null; String userId = obj.hasKey("userId") ? obj.getString("userId") : null; try {//from w w w.ja va 2 s . c o m authContext = getOrCreateContext(authority, validateAuthority); // We should retrieve userId from broker cache since local is always empty boolean useBroker = AuthenticationSettings.INSTANCE.getUseBroker(); if (useBroker) { if (TextUtils.isEmpty(userId)) { // Get first user from account list userId = authContext.getBrokerUser(); } for (UserInfo info : authContext.getBrokerUsers()) { if (info.getDisplayableId().equals(userId)) { userId = info.getUserId(); break; } } } } catch (Exception e) { callback.invoke(e.getMessage()); return; } authContext.acquireTokenSilentAsync(resourceId, clientId, userId, new DefaultAuthenticationCallback(callback)); }
From source file:com.microsoft.aad.adal.ReactNativeAdalPlugin.java
License:Open Source License
@ReactMethod public void tokenCacheReadItems(ReadableMap obj, Callback callback) throws JSONException { final AuthenticationContext authContext; String authority = obj.hasKey("authority") ? obj.getString("authority") : null; boolean validateAuthority = obj.hasKey("validateAuthority") ? obj.getBoolean("validateAuthority") : false; try {// w ww.j a v a 2 s. co m authContext = getOrCreateContext(authority, validateAuthority); } catch (Exception e) { callback.invoke(e.getMessage()); return; } WritableArray result = Arguments.createArray(); ITokenCacheStore cache = authContext.getCache(); if (cache instanceof ITokenStoreQuery) { Iterator<TokenCacheItem> cacheItems = ((ITokenStoreQuery) cache).getAll(); while (cacheItems.hasNext()) { TokenCacheItem item = cacheItems.next(); result.pushMap(tokenItemToJSON(item)); } } callback.invoke(null, result); }
From source file:com.microsoft.aad.adal.ReactNativeAdalPlugin.java
License:Open Source License
@ReactMethod public void tokenCacheDeleteItem(ReadableMap obj, Callback callback) { final AuthenticationContext authContext; String authority = obj.hasKey("authority") ? obj.getString("authority") : null; boolean validateAuthority = obj.hasKey("validateAuthority") ? obj.getBoolean("validateAuthority") : false; String resourceId = obj.hasKey("resourceId") ? obj.getString("resourceId") : null; String clientId = obj.hasKey("clientId") ? obj.getString("clientId") : null; String userId = obj.hasKey("userId") ? obj.getString("userId") : null; String itemAuthority = obj.hasKey("itemAuthority") ? obj.getString("itemAuthority") : null; boolean isMultipleResourceRefreshToken = obj.hasKey("isMultipleResourceRefreshToken") ? obj.getBoolean("isMultipleResourceRefreshToken") : false;/*from ww w . j a va 2 s. c o m*/ try { authContext = getOrCreateContext(authority, validateAuthority); } catch (Exception e) { callback.invoke(e.getMessage()); return; } String key = CacheKey.createCacheKey(itemAuthority, resourceId, clientId, isMultipleResourceRefreshToken, userId, "1"); authContext.getCache().removeItem(key); callback.invoke(); }
From source file:com.microsoft.aad.adal.ReactNativeAdalPlugin.java
License:Open Source License
@ReactMethod public void tokenCacheClear(ReadableMap obj, Callback callback) { final AuthenticationContext authContext; String authority = obj.hasKey("authority") ? obj.getString("authority") : null; boolean validateAuthority = obj.hasKey("validateAuthority") ? obj.getBoolean("validateAuthority") : false; try {//from www. j a v a 2 s.c o m authContext = getOrCreateContext(authority, validateAuthority); } catch (Exception e) { callback.invoke(e.getMessage()); return; } authContext.getCache().removeAll(); callback.invoke(); }
From source file:com.microsoft.aad.adal.ReactNativeAdalPlugin.java
License:Open Source License
@ReactMethod public void setUseBroker(ReadableMap obj, Callback callback) { boolean useBroker = obj.hasKey("useBroker") ? obj.getBoolean("useBroker") : false; this.permissionCallback = callback; try {/*from ww w . j av a 2 s . co m*/ AuthenticationSettings.INSTANCE.setUseBroker(useBroker); // Android 6.0 "Marshmallow" introduced a new permissions model where the user can turn on and off permissions as necessary. // This means that applications must handle these permission in run time. // http://cordova.apache.org/docs/en/latest/guide/platforms/android/plugin.html#android-permissions if (useBroker && Build.VERSION.SDK_INT >= 23 /* Build.VERSION_CODES.M */ ) { requestBrokerPermissions(); // Cordova callback will be handled by requestBrokerPermissions method } } catch (Exception e) { callback.invoke(e.getMessage()); } }
From source file:com.microsoft.appcenter.reactnative.analytics.ReactNativeUtils.java
License:Open Source License
public static JSONObject convertReadableMapToJsonObject(ReadableMap map) throws JSONException { JSONObject jsonObj = new JSONObject(); ReadableMapKeySetIterator it = map.keySetIterator(); while (it.hasNextKey()) { String key = it.nextKey(); ReadableType type = map.getType(key); switch (type) { case Map: jsonObj.put(key, convertReadableMapToJsonObject(map.getMap(key))); break; case Array: jsonObj.put(key, convertReadableArrayToJsonArray(map.getArray(key))); break; case String: jsonObj.put(key, map.getString(key)); break; case Number: Double number = map.getDouble(key); if ((number == Math.floor(number)) && !Double.isInfinite(number)) { jsonObj.put(key, number.longValue()); } else { jsonObj.put(key, number.doubleValue()); }/*w w w .j a v a2 s .c o m*/ break; case Boolean: jsonObj.put(key, map.getBoolean(key)); break; default: jsonObj.put(key, null); break; } } return jsonObj; }
From source file:com.microsoft.appcenter.reactnative.appcenter.ReactNativeUtils.java
License:Open Source License
private static Object toObject(@Nullable ReadableMap readableMap, String key) { if (readableMap == null) { return null; }/*from w ww. ja va 2 s . c o m*/ Object result; ReadableType readableType = readableMap.getType(key); switch (readableType) { case Null: result = null; break; case Boolean: result = readableMap.getBoolean(key); break; case Number: // Can be int or double. double tmp = readableMap.getDouble(key); if (tmp == (int) tmp) { result = (int) tmp; } else { result = tmp; } break; case String: result = readableMap.getString(key); break; case Map: result = toMap(readableMap.getMap(key)); break; //case Array: // result = toList(readableMap.getArray(key)); // break; default: throw new IllegalArgumentException("Could not convert object with key: " + key + "."); } return result; }