Skip to content
Draft
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
65 changes: 65 additions & 0 deletions src/plugins/pluginContext/src/android/Tee.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

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

public class Tee extends CordovaPlugin {

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



private Context context;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing import for Context

Suggested change
private Context context;
import android.content.Context;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaWebView;

Add these imports after line 16 (after the java.util imports)



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 +124,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(token, key, defaultValue = "") {
return new Promise((resolve, reject) => {
exec(
resolve,
reject,
"Tee",
"get_secret",
[token, key, defaultValue]
);
});
}
Comment on lines +38 to +48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

token parameter is redundant - should use this.uuid like other methods

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



setSecret(token, key, value) {
return new Promise((resolve, reject) => {
exec(
resolve,
reject,
"Tee",
"set_secret",
[token, key, value]
);
});
}
Comment on lines +51 to +61
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

token parameter is redundant - should use this.uuid like other methods

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

}

//Object.freeze(this);
Expand Down