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 7, 2015
1 parent 5e6d3c7 commit 9905923
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
12 changes: 5 additions & 7 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,21 @@
<framework src="SystemConfiguration.framework" />
<framework src="MobileCoreServices.framework" />

<config-file target="*-Info.plist" parent="ApiUser">
<config-file target="*-Info.plist" parent="SendGridApiUser">
<string>$API_USER</string>
</config-file>

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

</platform>

<platform name="android">

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

<config-file target="res/values/sendgrid.xml" parent="/*">
<string name="api_user">$API_USER</string>
<string name="api_key">$API_KEY</string>
<config-file target="res/values/strings.xml" parent="/*">
<string name="sendgrid_api_user">$API_USER</string>
<string name="sendgrid_api_key">$API_KEY</string>
</config-file>

<config-file target="res/xml/config.xml" parent="/*">
Expand Down
4 changes: 2 additions & 2 deletions src/android/SendGridPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo

private void send(final CallbackContext callbackContext, final JSONObject jsonObject) throws JSONException, IOException {

int appResId = cordova.getActivity().getResources().getIdentifier("api_user", "string", cordova.getActivity().getPackageName());
int appResId = cordova.getActivity().getResources().getIdentifier("sendgrid_api_user", "string", cordova.getActivity().getPackageName());
String apiUser = cordova.getActivity().getString(appResId);

appResId = cordova.getActivity().getResources().getIdentifier("api_key", "string", cordova.getActivity().getPackageName());
appResId = cordova.getActivity().getResources().getIdentifier("sendgrid_api_key", "string", cordova.getActivity().getPackageName());

String apiKey = cordova.getActivity().getString(appResId);

Expand Down
3 changes: 0 additions & 3 deletions src/android/res/values/sendgrid.xml

This file was deleted.

4 changes: 2 additions & 2 deletions src/ios/CDVSendGrid.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ - (void)sendWithWeb:(CDVInvokedUrlCommand*)command
NSDictionary* body = [command.arguments objectAtIndex:0];

if (body != nil) {
NSString *apiUser = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"ApiUser"];
NSString *apiKey = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"ApiKey"];
NSString *apiUser = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"SendGridApiUser"];
NSString *apiKey = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"SendGridApiKey"];

SendGrid *sendGrid = [SendGrid apiUser:apiUser apiKey:apiKey];

Expand Down

0 comments on commit 9905923

Please sign in to comment.