Skip to content

Commit

Permalink
RMET-2800 ::: iOS ::: Add new GIDClientID Property (#49)
Browse files Browse the repository at this point in the history
* chore: New Google Client ID for iOS library

Update 'OSSocialLoginsLib.xcframework' to the latest version. For Google Sign-in, this requires a new property for the 'Info.plist' file: 'GIDClientID'. This is set, if configured, through the 'iOSCopyPreference' hook, based on the Google URL Scheme value.
Do some refactoring to the 'iOSCopyPreferences' hook and 'plugin.xml', removing redundant code and unneeded placeholders.

References: https://outsystemsrd.atlassian.net/browse/RMET-2800

* chore: Add CHANGELOG entry

References: https://outsystemsrd.atlassian.net/browse/RMET-2800
  • Loading branch information
OS-ricardomoreirasilva committed Mar 4, 2024
1 parent a8b5137 commit eb30073
Show file tree
Hide file tree
Showing 23 changed files with 11,145 additions and 97 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ The changes documented here do not include those from the original repository.

## [Unreleased]

### 2024-02-29
- Chore: [iOS] Set the new `GIDClientID` property for `plist` file. This is required for `Google Sign-In` version `7.0.0` (https://outsystemsrd.atlassian.net/browse/RMET-2800).

### 2024-01-30
- Fix: [iOS] Unable for an app to route into the screen mentioned in the deep link (using the `ApplicationID`). (https://outsystemsrd.atlassian.net/browse/RMET-3139)

Expand Down
74 changes: 49 additions & 25 deletions hooks/iOSCopyPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,28 @@ const { Console } = require('console');

const {getJsonFile, ProvidersEnum, ApplicationTypeEnum} = require('./utils');

function reverseURLScheme(str) {
// Step 1. Use the split() method to return a new array
var splitString = str.split("."); // split "hello.world"
// ["hello", "world"]

// Step 2. Use the reverse() method to reverse the new created array
var reverseArray = splitString.reverse(); // reverse ["hello", "world"]
// ["world", "hello"]

// Step 3. Use the join() method to join all elements of the array into a string
var joinArray = reverseArray.join("."); // join ["world", "hello"]
// "world.hello"

//Step 4. Return the reversed string
return joinArray;
}

module.exports = async function (context) {
var projectRoot = context.opts.cordova.project ? context.opts.cordova.project.root : context.opts.projectRoot;

var google_url_scheme = "";
var google_client_id = "";

var facebook_client_appId = "";
var facebook_client_token = "";
Expand Down Expand Up @@ -40,6 +58,7 @@ module.exports = async function (context) {

if (configItem.url_scheme != null && configItem.url_scheme !== "") {
google_url_scheme = configItem.url_scheme;
google_client_id = reverseURLScheme(google_url_scheme);
} else {
googleErrorArray.push('URL Scheme');
}
Expand Down Expand Up @@ -92,38 +111,43 @@ module.exports = async function (context) {
var infoPlistFile = fs.readFileSync(infoPlistPath, 'utf8');
var infoPlist = plist.parse(infoPlistFile);

const initialCFBundleURLTypeArray = infoPlist['CFBundleURLTypes'];
var finalCFBundleURLTypeArray = [];
initialCFBundleURLTypeArray.forEach(function(item) {
if (item['CFBundleURLName'] == 'Google') {
if (google_url_scheme != '') {
item['CFBundleURLSchemes'] = [google_url_scheme];
finalCFBundleURLTypeArray.push(item);
}
} else if (item['CFBundleURLName'] == 'Facebook') {
if (facebook_client_appId != '') {
item['CFBundleURLSchemes'] = ['fb' + facebook_client_appId];
finalCFBundleURLTypeArray.push(item);
}
} else if (item['CFBundleURLName'] == 'DeepLinkScheme') {
item['CFBundleURLSchemes'] = [deeplink_url_scheme];
finalCFBundleURLTypeArray.push(item);
} else {
finalCFBundleURLTypeArray.push(item);
}
});
infoPlist['CFBundleURLTypes'] = finalCFBundleURLTypeArray;
var cfbundleURLTypeArray = infoPlist['CFBundleURLTypes'];

const deepLinkSchemeHashMap = {
'CFBundleURLName': 'DeepLinkScheme',
'CFBundleURLSchemes': [deeplink_url_scheme]
};
cfbundleURLTypeArray.push(deepLinkSchemeHashMap);

if (google_url_scheme != '') {
const googleURLSchemeHashMap = {
'CFBundleURLName': 'Google',
'CFBundleURLSchemes': [google_url_scheme]
};

cfbundleURLTypeArray.push(googleURLSchemeHashMap);
}

if (facebook_client_appId != '') {
const facebookClientAppIdHashMap = {
'CFBundleURLName': 'Facebook',
'CFBundleURLSchemes': ['fb' + facebook_client_appId]
};

cfbundleURLTypeArray.push(facebookClientAppIdHashMap);
}
infoPlist['CFBundleURLTypes'] = cfbundleURLTypeArray;

if (facebook_client_appId != '') {
infoPlist['FacebookAppID'] = facebook_client_appId
} else {
delete infoPlist['FacebookAppID'];
}

if (facebook_client_token != '') {
infoPlist['FacebookClientToken'] = facebook_client_token;
} else {
delete infoPlist['FacebookClientToken'];
}

if (google_client_id != '') {
infoPlist['GIDClientID'] = google_client_id;
}

fs.writeFileSync(infoPlistPath, plist.build(infoPlist, { indent: '\t' }));
Expand Down
39 changes: 0 additions & 39 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,45 +74,6 @@
<preference name="UseSwiftLanguageVersion" value="5" />
</config-file>

<config-file target="*-Info.plist" parent="CFBundleURLTypes">
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>Google</string>
<key>CFBundleURLSchemes</key>
<array>
<string>GOOGLE_CLIENT_ID</string>
</array>
</dict>
<dict>
<key>CFBundleURLName</key>
<string>Facebook</string>
<key>CFBundleURLSchemes</key>
<array>
<string>FACEBOOK_CLIENT_URLSCHEME</string>
</array>
</dict>
<dict>
<key>CFBundleURLName</key>
<string>DeepLinkScheme</string>
<key>CFBundleURLSchemes</key>
<array>
<string>DEEP_LINK_URLSCHEME</string>
</array>
</dict>
</array>
</config-file>

<config-file target="*-Info.plist" parent="FacebookAppID">
<string>FACEBOOK_CLIENT_APPID</string>
</config-file>

<config-file target="*-Info.plist" parent="FacebookClientToken">
<string>FACEBOOK_CLIENT_TOKEN</string>
</config-file>

<config-file target="*-Info.plist" parent="LSApplicationQueriesSchemes">
<array>
<string>fbapi</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Generated by Apple Swift version 5.6.1 (swiftlang-5.6.0.323.66 clang-1316.0.20.12)
#if 0
#elif defined(__arm64__) && __arm64__
// Generated by Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)
#ifndef OSSOCIALLOGINSLIB_SWIFT_H
#define OSSOCIALLOGINSLIB_SWIFT_H
#pragma clang diagnostic push
Expand All @@ -21,11 +23,20 @@
# include <swift/objc-prologue.h>
#endif

#pragma clang diagnostic ignored "-Wduplicate-method-match"
#pragma clang diagnostic ignored "-Wauto-import"
#if defined(__OBJC__)
#include <Foundation/Foundation.h>
#endif
#if defined(__cplusplus)
#include <cstdint>
#include <cstddef>
#include <cstdbool>
#else
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#endif

#if !defined(SWIFT_TYPEDEFS)
# define SWIFT_TYPEDEFS 1
Expand Down Expand Up @@ -181,16 +192,40 @@ typedef unsigned int swift_uint4 __attribute__((__ext_vector_type__(4)));
#else
# define SWIFT_DEPRECATED_OBJC(Msg) SWIFT_DEPRECATED_MSG(Msg)
#endif
#if defined(__OBJC__)
#if !defined(IBSegueAction)
# define IBSegueAction
#endif
#endif
#if !defined(SWIFT_EXTERN)
# if defined(__cplusplus)
# define SWIFT_EXTERN extern "C"
# else
# define SWIFT_EXTERN extern
# endif
#endif
#if !defined(SWIFT_CALL)
# define SWIFT_CALL __attribute__((swiftcall))
#endif
#if defined(__cplusplus)
#if !defined(SWIFT_NOEXCEPT)
# define SWIFT_NOEXCEPT noexcept
#endif
#else
#if !defined(SWIFT_NOEXCEPT)
# define SWIFT_NOEXCEPT
#endif
#endif
#if defined(__cplusplus)
#if !defined(SWIFT_CXX_INT_DEFINED)
#define SWIFT_CXX_INT_DEFINED
namespace swift {
using Int = ptrdiff_t;
using UInt = size_t;
}
#endif
#endif
#if defined(__OBJC__)
#if __has_feature(modules)
#if __has_warning("-Watimport-in-framework-header")
#pragma clang diagnostic ignored "-Watimport-in-framework-header"
Expand All @@ -201,13 +236,15 @@ typedef unsigned int swift_uint4 __attribute__((__ext_vector_type__(4)));
@import UIKit;
#endif

#endif
#pragma clang diagnostic ignored "-Wproperty-attribute-mismatch"
#pragma clang diagnostic ignored "-Wduplicate-method-arg"
#if __has_warning("-Wpragma-clang-attribute")
# pragma clang diagnostic ignored "-Wpragma-clang-attribute"
#endif
#pragma clang diagnostic ignored "-Wunknown-pragmas"
#pragma clang diagnostic ignored "-Wnullability"
#pragma clang diagnostic ignored "-Wdollar-in-identifier-extension"

#if __has_attribute(external_source_symbol)
# pragma push_macro("any")
Expand All @@ -216,6 +253,7 @@ typedef unsigned int swift_uint4 __attribute__((__ext_vector_type__(4)));
# pragma pop_macro("any")
#endif

#if defined(__OBJC__)



Expand Down Expand Up @@ -280,8 +318,15 @@ SWIFT_CLASS("_TtC17OSSocialLoginsLib30SocialLoginsLinkedInController")
@end


#endif
#if defined(__cplusplus)
#endif
#if __has_attribute(external_source_symbol)
# pragma clang attribute pop
#endif
#pragma clang diagnostic pop
#endif

#else
#error unsupported Swift architecture
#endif
Binary file not shown.
Loading

0 comments on commit eb30073

Please sign in to comment.