Giter VIP home page Giter VIP logo

stadionhq / react-native-gigya-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from colorfy-software/react-native-gigya-sdk

0.0 1.0 0.0 525 KB

๐ŸŒค SAP CDC/Gigya SDK for your React Native applications.

Home Page: https://www.npmjs.com/package/react-native-gigya-sdk

License: MIT License

Java 18.34% JavaScript 1.64% TypeScript 58.23% Swift 13.00% C 0.12% Objective-C 7.24% Ruby 1.43%

react-native-gigya-sdk's Introduction

SAP CDC/Gigya SDK for your React Native applications.

Current GitHub Actions build status. Current npm package version. Monthly npm downloads. PRs welcome!

๐Ÿ—๏ธ Installation

  1. Install the library :
yarn add react-native-gigya-sdk
  1. 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() and setItem() functions.

iOS

See steps
  1. Add the following line to your ios/Podfile:
pod 'Gigya'
  1. From /ios, run:
pod install
  1. If you don't already one, via Xcode, add a .swift file to your Xcode project and accept to Create Bridging Header:
//
//  Bridge.swift
//  GigyaSdkExample
//

import Foundation
  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 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()
        }
    }
  2. 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!
        }
    }

Android

See steps
  1. Add the desired Gigya SDK version to your android/build.gradle:
buildscript {
    ext {
      gigyaCoreSdkVersion = "core-v5.0.1"
    }
}
  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.

๐Ÿ’ป Usage

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)

๐Ÿค Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

๐Ÿ“ฐ License

MIT

react-native-gigya-sdk's People

Contributors

charlesmangwa avatar stefandbd avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.