1515import java .util .Set ;
1616import java .util .concurrent .ConcurrentHashMap ;
1717
18+ //auth plugin
19+ import com .foxdebug .acode .rk .auth .EncryptedPreferenceManager ;
20+
1821public class Tee extends CordovaPlugin {
1922
2023 // pluginId : token
@@ -26,10 +29,62 @@ public class Tee extends CordovaPlugin {
2629 // token : list of permissions
2730 private /*static*/ final Map <String , List <String >> permissionStore = new ConcurrentHashMap <>();
2831
32+
33+
34+ private Context context ;
35+
36+
37+ public void initialize (CordovaInterface cordova , CordovaWebView webView ) {
38+ super .initialize (cordova , webView );
39+ this .context = cordova .getContext ();
40+ }
41+
2942 @ Override
3043 public boolean execute (String action , JSONArray args , CallbackContext callback )
3144 throws JSONException {
3245
46+
47+ if ("get_secret" .equals (action )) {
48+ String token = args .getString (0 );
49+ String key = args .getString (1 );
50+ String defaultValue = args .getString (2 );
51+
52+ String pluginId = getPluginIdFromToken (token );
53+
54+ if (pluginId == null ) {
55+ callback .error ("INVALID_TOKEN" );
56+ return true ;
57+ }
58+
59+ EncryptedPreferenceManager prefs =
60+ new EncryptedPreferenceManager (context , pluginId );
61+
62+ String value = prefs .getString (key , defaultValue );
63+ callback .success (value );
64+ return true ;
65+ }
66+
67+ if ("set_secret" .equals (action )) {
68+ String token = args .getString (0 );
69+ String key = args .getString (1 );
70+ String value = args .getString (2 );
71+
72+ String pluginId = getPluginIdFromToken (token );
73+
74+ if (pluginId == null ) {
75+ callback .error ("INVALID_TOKEN" );
76+ return true ;
77+ }
78+
79+ EncryptedPreferenceManager prefs =
80+ new EncryptedPreferenceManager (context , pluginId );
81+
82+ prefs .setString (key , value );
83+ callback .success ();
84+ return true ;
85+ }
86+
87+
3388 if ("requestToken" .equals (action )) {
3489 String pluginId = args .getString (0 );
3590 String pluginJson = args .getString (1 );
@@ -69,6 +124,16 @@ public boolean execute(String action, JSONArray args, CallbackContext callback)
69124 return false ;
70125 }
71126
127+
128+ private String getPluginIdFromToken (String token ) {
129+ for (Map .Entry <String , String > entry : tokenStore .entrySet ()) {
130+ if (entry .getValue ().equals (token )) {
131+ return entry .getKey ();
132+ }
133+ }
134+ return null ;
135+ }
136+
72137 //============================================================
73138 //do not change function signatures
74139 public boolean isTokenValid (String token , String pluginId ) {
0 commit comments