Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/plugins/pluginContext/src/android/Tee.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import android.content.Context;
import org.apache.cordova.*;

//auth plugin
import com.foxdebug.acode.rk.auth.EncryptedPreferenceManager;

public class Tee extends CordovaPlugin {

Expand All @@ -26,10 +31,62 @@ public class Tee extends CordovaPlugin {
// token : list of permissions
private /*static*/ final Map<String, List<String>> permissionStore = new ConcurrentHashMap<>();



private Context context;


public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
this.context = cordova.getContext();
}

@Override
public boolean execute(String action, JSONArray args, CallbackContext callback)
throws JSONException {


if ("get_secret".equals(action)) {
String token = args.getString(0);
String key = args.getString(1);
String defaultValue = args.getString(2);

String pluginId = getPluginIdFromToken(token);

if (pluginId == null) {
callback.error("INVALID_TOKEN");
return true;
}

EncryptedPreferenceManager prefs =
new EncryptedPreferenceManager(context, pluginId);

String value = prefs.getString(key, defaultValue);
callback.success(value);
return true;
}

if ("set_secret".equals(action)) {
String token = args.getString(0);
String key = args.getString(1);
String value = args.getString(2);

String pluginId = getPluginIdFromToken(token);

if (pluginId == null) {
callback.error("INVALID_TOKEN");
return true;
}

EncryptedPreferenceManager prefs =
new EncryptedPreferenceManager(context, pluginId);

prefs.setString(key, value);
callback.success();
return true;
}


if ("requestToken".equals(action)) {
String pluginId = args.getString(0);
String pluginJson = args.getString(1);
Expand Down Expand Up @@ -69,6 +126,16 @@ public boolean execute(String action, JSONArray args, CallbackContext callback)
return false;
}


private String getPluginIdFromToken(String token) {
for (Map.Entry<String, String> entry : tokenStore.entrySet()) {
if (entry.getValue().equals(token)) {
return entry.getKey();
}
}
return null;
}

//============================================================
//do not change function signatures
public boolean isTokenValid(String token, String pluginId) {
Expand Down
25 changes: 25 additions & 0 deletions src/plugins/pluginContext/www/PluginContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@ const PluginContext = (function () {
exec(resolve, reject, "Tee", "listAllPermissions", [this.uuid]);
});
}

getSecret(key, defaultValue = "") {
return new Promise((resolve, reject) => {
exec(
resolve,
reject,
"Tee",
"get_secret",
[this.uuid, key, defaultValue]
);
});
}


setSecret(key, value) {
return new Promise((resolve, reject) => {
exec(
resolve,
reject,
"Tee",
"set_secret",
[this.uuid, key, value]
);
});
}
}

//Object.freeze(this);
Expand Down