Skip to content

Commit

Permalink
Rename ApiKey resource identifiers to avoid collisions with other plu…
Browse files Browse the repository at this point in the history
…gins

* api_key is too generic and has high probability to collide
* [Android] installing with plugman's --link option makes all projects leak their keys into the same source file. It's better to add the key in strings.xml
  • Loading branch information
Martin Bektchiev committed Dec 2, 2015
1 parent 3d2e24e commit 983c56e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
8 changes: 3 additions & 5 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,16 @@
<header-file src="src/ios/CDVStripe.h" />
<source-file src="src/ios/CDVStripe.m" />

<config-file target="*-Info.plist" parent="ApiKey">
<config-file target="*-Info.plist" parent="StripeApiKey">
<string>$API_KEY</string>
</config-file>

</platform>

<platform name="android">

<source-file src="src/android/res/values/stripe.xml" target-dir="res/values" />

<config-file target="res/values/stripe.xml" parent="/*">
<string name="api_key">$API_KEY</string>
<config-file target="res/values/strings.xml" parent="/*">
<string name="stripe_api_key">$API_KEY</string>
</config-file>

<config-file target="res/xml/config.xml" parent="/*">
Expand Down
2 changes: 1 addition & 1 deletion src/android/StripePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo

private void processCommand(final CallbackContext callbackContext, final JSONArray args) throws JSONException, UnsupportedEncodingException {

int appResId = cordova.getActivity().getResources().getIdentifier("api_key", "string", cordova.getActivity().getPackageName());
int appResId = cordova.getActivity().getResources().getIdentifier("stripe_api_key", "string", cordova.getActivity().getPackageName());
String apiKey = cordova.getActivity().getString(appResId);

final HttpClient httpclient = new DefaultHttpClient();
Expand Down
3 changes: 0 additions & 3 deletions src/android/res/values/stripe.xml

This file was deleted.

2 changes: 1 addition & 1 deletion src/ios/CDVStripe.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ - (void)sendAsynchronousRequest:(NSURL*)url method:(NSString*)method dictionary:

[request setHTTPMethod:method];

NSString *apiKey = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"ApiKey"];
NSString *apiKey = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"StripeApiKey"];

NSString *authStr = [NSString stringWithFormat:@"%@:", apiKey];
NSData *authData = [authStr dataUsingEncoding:NSUTF8StringEncoding];
Expand Down

0 comments on commit 983c56e

Please sign in to comment.