- Install the library :
yarn add react-native-gigya-sdk
- If you haven't done so already, install a persistent storage library (like EncryptedStorage) as you'll need to provide it during setup. Just make sure your library exposes
getItem()
andsetItem()
functions.
See steps
- Add the following line to your
ios/Podfile
:
pod 'Gigya'
- From
/ios
, run:
pod install
- If you don't already one, via Xcode, add a
.swift
file to your Xcode project and accept toCreate Bridging Header
:
//
// Bridge.swift
// GigyaSdkExample
//
import Foundation
-
If you're planing on providing Facebook login, search for the "Facebook" section and follow the full documentation to install and set up the Facebook SDK. You can then create a
FacebookWrapper.swift
file from Xcode and add it to your target (inside Compile Sources from the Build Phases tab) to handle the communication with the SDK. The file could look like so:See file
// // FacebookWrapper.swift // GigyaSdk // // Created by Charles Mangwa on 30.06.21. // Copyright Β© 2021 colorfy GmbH. All rights reserved. // import Foundation import FBSDKCoreKit import FBSDKLoginKit import Gigya class FacebookWrapper: ProviderWrapperProtocol { private var completionHandler: (_ jsonData: [String: Any]?, _ error: String?) -> Void = { _, _ in } var clientID: String? private let defaultReadPermissions = ["email"] lazy var fbLogin: LoginManager = { return LoginManager() }() required init() { } func login(params: [String: Any]?, viewController: UIViewController?, completion: @escaping (_ jsonData: [String: Any]?, _ error: String?) -> Void) { completionHandler = completion fbLogin.logIn(permissions: defaultReadPermissions, from: viewController) { (result, error) in if result?.isCancelled != false { completion(nil, "sign in cancelled") return } if let error = error { completion(nil, error.localizedDescription) } let jsonData: [String: Any] = ["accessToken": result?.token?.tokenString ?? "", "tokenExpiration": result?.token?.expirationDate.timeIntervalSince1970 ?? 0] completion(jsonData, nil) } } func logout() { fbLogin.logOut() } }
-
Same if you want Apple Sign In, search for the "Apple" section and follow the full documentation here and create a
AppleSignInWrapper.swift
file in the same manner as explained above. The file could look like so:See file
// // AppleSignInWrapper.swift // GigyaSdk // // Created by Charles Mangwa on 30.06.21. // Copyright Β© 2021 colorfy GmbH. All rights reserved. // import Foundation import Gigya import AuthenticationServices @available(iOS 13.0, *) class AppleSignInWrapper: NSObject, ProviderWrapperProtocol { var clientID: String? private lazy var appleLogin: AppleSignInInternalWrapper = { return AppleSignInInternalWrapper() }() required override init() { super.init() } func login(params: [String : Any]?, viewController: UIViewController?, completion: @escaping ([String : Any]?, String?) -> Void) { appleLogin.login(params: params, viewController: viewController, completion: completion) } } @available(iOS 13.0, *) private class AppleSignInInternalWrapper: NSObject { lazy var appleIDProvider: ASAuthorizationAppleIDProvider = { return ASAuthorizationAppleIDProvider() }() weak var viewController: UIViewController? private var completionHandler: (_ jsonData: [String: Any]?, _ error: String?) -> Void = { _, _ in } func login(params: [String : Any]?, viewController: UIViewController?, completion: @escaping ([String : Any]?, String?) -> Void) { self.completionHandler = completion self.viewController = viewController let appleIDProvider = ASAuthorizationAppleIDProvider() let request = appleIDProvider.createRequest() request.requestedScopes = [.fullName, .email] let authorizationController = ASAuthorizationController(authorizationRequests: [request]) authorizationController.delegate = self authorizationController.presentationContextProvider = self authorizationController.performRequests() } } @available(iOS 13.0, *) extension AppleSignInInternalWrapper: ASAuthorizationControllerDelegate { func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) { if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential { if let authorizationCode = appleIDCredential.authorizationCode, let identityToken = appleIDCredential.identityToken { let authorizationCodeEncoded = String(decoding: authorizationCode, as: UTF8.self) let identityTokenEncoded = String(decoding: identityToken, as: UTF8.self) var jsonData: [String: Any] = ["code": authorizationCodeEncoded, "accessToken": identityTokenEncoded] if let firstName = appleIDCredential.fullName?.givenName { jsonData["firstName"] = firstName } if let lastName = appleIDCredential.fullName?.familyName { jsonData["lastName"] = lastName } completionHandler(jsonData, nil) } else { completionHandler(nil, "can't getting params from Apple") } } } func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) { completionHandler(nil, error.localizedDescription) } } @available(iOS 13.0, *) extension AppleSignInInternalWrapper: ASAuthorizationControllerPresentationContextProviding { func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor { return self.viewController!.view.window! } }
See steps
- Add the desired Gigya SDK version to your
android/build.gradle
:
buildscript {
ext {
gigyaCoreSdkVersion = "core-v5.0.1"
}
}
- If you're planing on providing Facebook login, search for the "Facebook" section and follow the full documentation to install and set up the Facebook SDK.
You can now initialize the SDK with your apiKey
,
dataCenter
, application
lang
,
storage
solution & desired storageKey.
β Please make sure your storage library exposes getItem()
and setItem()
functions.
import GigyaSdk from 'react-native-gigya-sdk'
import EncryptedStorage from 'react-native-encrypted-storage'
// Before anything we initialize the SDK.
GigyaSdk.init({
lang: 'en',
apiKey: 'INSERT_GIGYA_API_KEY',
dataCenter: 'eu1.gigya.com',
storage: EncryptedStorage,
storageKey: 'RANDOM_STRING'
})
// Now we can use it.
const myAccount = await GigyaSdk.login(email, password)
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT