Skip to content

Commit

Permalink
(iOS) Set the Sign In with Apple capability based on the IOS_ENABLE_A…
Browse files Browse the repository at this point in the history
…PPLE_SIGNIN plugin variable. Resolves dpa99c#511.
  • Loading branch information
Dave Alden committed Sep 16, 2020
1 parent 3de7a8a commit e7f9a0a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ See [Specifying Android library versions](#specifying-android-library-versions)
- Note: Firebase Messaging iOS SDK version 7.0 will be a breaking change where the SDK will no longer support iOS Direct Channel API.
- `IOS_FIREBASE_CONFIG_FILEPATH` - sets a custom filepath to `GoogleService-Info.plist` file as a path relative to the project root
- e.g. `--variable IOS_FIREBASE_CONFIG_FILEPATH="resources/ios/GoogleService-Info.plist"`
- `IOS_ENABLE_APPLE_SIGNIN` - enables the Sign In with Apple capability in Xcode.
- `--variable IOS_ENABLE_APPLE_SIGNIN=true`
- Ensure the associated app provisioning profile also has this capability enabled.

## Supported Cordova Versions
- cordova: `>= 9`
Expand Down Expand Up @@ -2605,6 +2608,11 @@ For details how to do the above, see the [Google Sign-In on Android page](https:
### authenticateUserWithApple
Authenticates the user with an Apple account using Sign In with Apple to obtain a credential that can be used to sign the user in/link to an existing user account/reauthenticate the user.

To use Sign In with Apple you must ensure your app's provisioning profile has this capability and it is enabled in your Xcode project.
You can enable the capability in Xcode by setting the `IOS_ENABLE_APPLE_SIGNIN` plugin variable at plugin installation time:

cordova plugin add cordova-plugin-firebasex --variable IOS_ENABLE_APPLE_SIGNIN=true

**Parameters**:
- {function} success - callback function to pass {object} credentials to as an argument. The credential object has the following properties:
- {string} id - the identifier of a native credential object which can be used for signing in the user.
Expand Down
11 changes: 1 addition & 10 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,7 @@
<param name="onload" value="true" />
</feature>
</config-file>
<config-file target="*/Entitlements-Debug.plist" parent="com.apple.developer.applesignin">
<array>
<string>Default</string>
</array>
</config-file>
<config-file target="*/Entitlements-Release.plist" parent="com.apple.developer.applesignin">
<array>
<string>Default</string>
</array>
</config-file>

<config-file target="*/Entitlements-Debug.plist" parent="aps-environment">
<string>development</string>
</config-file>
Expand Down
4 changes: 3 additions & 1 deletion scripts/after_prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ var PLATFORM = {
'www/GoogleService-Info.plist'
],
appPlist: IOS_DIR + '/' + appName + '/'+appName+'-Info.plist',
entitlementsDebugPlist: IOS_DIR + '/' + appName + '/Entitlements-Debug.plist',
entitlementsReleasePlist: IOS_DIR + '/' + appName + '/Entitlements-Release.plist',
},
ANDROID: {
dest: ANDROID_DIR + '/app/google-services.json',
Expand Down Expand Up @@ -161,6 +163,6 @@ module.exports = function (context) {
if(pluginVariables['IOS_STRIP_DEBUG'] && pluginVariables['IOS_STRIP_DEBUG'] === 'true'){
helper.stripDebugSymbols();
}
helper.applyPluginVarsToPlists(PLATFORM.IOS.dest, PLATFORM.IOS.appPlist, pluginVariables);
helper.applyPluginVarsToPlists(pluginVariables, PLATFORM.IOS);
}
};
24 changes: 18 additions & 6 deletions scripts/ios/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,14 @@ module.exports = {
console.log('cordova-plugin-firebasex: Applied IOS_STRIP_DEBUG to Podfile');
}
},
applyPluginVarsToPlists: function(googlePlistPath, appPlistPath, pluginVariables){
var googlePlist = plist.parse(fs.readFileSync(path.resolve(googlePlistPath), 'utf8')),
appPlist = plist.parse(fs.readFileSync(path.resolve(appPlistPath), 'utf8')),
applyPluginVarsToPlists: function(pluginVariables, iosPlatform){
var googlePlist = plist.parse(fs.readFileSync(path.resolve(iosPlatform.dest), 'utf8')),
appPlist = plist.parse(fs.readFileSync(path.resolve(iosPlatform.appPlist), 'utf8')),
entitlementsDebugPlist = plist.parse(fs.readFileSync(path.resolve(iosPlatform.entitlementsDebugPlist), 'utf8')),
entitlementsReleasePlist = plist.parse(fs.readFileSync(path.resolve(iosPlatform.entitlementsReleasePlist), 'utf8')),
googlePlistModified = false,
appPlistModified = false;
appPlistModified = false,
entitlementsPlistsModified = false;

if(typeof pluginVariables['FIREBASE_ANALYTICS_COLLECTION_ENABLED'] !== 'undefined'){
googlePlist["FIREBASE_ANALYTICS_COLLECTION_ENABLED"] = (pluginVariables['FIREBASE_ANALYTICS_COLLECTION_ENABLED'] !== "false" ? "true" : "false") ;
Expand Down Expand Up @@ -231,8 +234,17 @@ module.exports = {
appPlist['CFBundleURLTypes'][i] = entry;
appPlistModified = true;
}
if(pluginVariables['IOS_ENABLE_APPLE_SIGNIN'] === 'true'){
entitlementsDebugPlist["com.apple.developer.applesignin"] = ["Default"];
entitlementsReleasePlist["com.apple.developer.applesignin"] = ["Default"];
entitlementsPlistsModified = true;
}

if(googlePlistModified) fs.writeFileSync(path.resolve(googlePlistPath), plist.build(googlePlist));
if(appPlistModified) fs.writeFileSync(path.resolve(appPlistPath), plist.build(appPlist));
if(googlePlistModified) fs.writeFileSync(path.resolve(iosPlatform.dest), plist.build(googlePlist));
if(appPlistModified) fs.writeFileSync(path.resolve(iosPlatform.appPlist), plist.build(appPlist));
if(entitlementsPlistsModified){
fs.writeFileSync(path.resolve(iosPlatform.entitlementsDebugPlist), plist.build(entitlementsDebugPlist));
fs.writeFileSync(path.resolve(iosPlatform.entitlementsReleasePlist), plist.build(entitlementsReleasePlist));
}
}
};

0 comments on commit e7f9a0a

Please sign in to comment.