Coder Social home page Coder Social logo

eneskaraosman / sociallogins Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 1.0 2.41 MB

Makes social logins easier for iOS

License: MIT License

Ruby 10.25% Swift 89.75%
login apple-login google-login sign-in-with-apple sign-in-with-google sign-in social-login

sociallogins's Introduction

SocialLogins

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

SocialLogins is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SocialLogins'

Preview

Usage

Before performing sign in actions, make sure you set following;

Note: Use SocialLogins shared instance in AppDelegate & SceneDelegate

Set in AppDelegate.swift

func application(
    _ application: UIApplication, 
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {

    // Required if you're using GoogleSignIn, otherwise no need to call.
    SocialLogins.shared.configure(clientID: "")
    let _ = SocialLogins.shared.application(
        application,
        didFinishLaunchingWithOptions: launchOptions
    )
    
}

func application(
    _ app: UIApplication, 
    open url: URL, 
    options: [UIApplicationOpenURLOptionsKey : Any] = [:]
) -> Bool {
    return SocialLogins.shared.application(
        app,
        open: url,
        options: options
    )
}

Set in SceneDelegate.swift (if SceneDelegate exist, otherwise no need to create)

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    
    SocialLogins.shared.scene(
        scene,
        openURLContexts: openURLContexts
    )
}

If you implement methods above, no need to re implement them while following Google & Facebook instructions. (Just configure URL Schemes & Info.plist)

  • Make sure to add URL scheme, TARGETS > Info > URL Types > + (Add)
  • Facebook
    Facebook Login SDK integration Make sure to follow link;
    You'll need to create an app from facebook developer & communicate with your project. Modify Info.plist & URL Scheme

Available Sign In Methods

  • Apple
  • Google
  • Facebook

You can create your own LoginViewModel

import SocialLogins
import FirebaseAuth // Imagine we'll send provided info to Firebase

class MyLoginViewModel: SocialLogins.LoginViewModel {
    
    override init() {
        super.init()
    }
    
    override func completeSignIn(with authResult: SocialLogins.AuthResult) {
        super.completeSignIn(with: authResult)
        
        // Here you may send credentials to different backend, instead Firebase.
        func signInToFirebase(with credential: AuthCredential) {
            Auth.auth().signIn(with: credential) { (result, error) in
                if let user = result?.user {
                    print("**** \(self.selectedSignInMethod.rawValue) sign in succeeded")
                    self.signInSucceeded = true
                }
            }
        }
        
        switch selectedSignInMethod {
        case .apple:
            let credential = OAuthProvider.credential(
                withProviderID: "apple.com",
                idToken: authResult.idToken!,
                rawNonce: authResult.rawNonce
            )
            signInToFirebase(with: credential)
        case .google:
            let credential = GoogleAuthProvider.credential(
                withIDToken: authResult.idToken!,
                accessToken: authResult.accessToken!
            )
            signInToFirebase(with: credential)
        case .facebook:
            let credential = FacebookAuthProvider.credential(
                withAccessToken: authResult.accessToken!
            )
            signInToFirebase(with: credential)
        case .none: break
        }
    }
    
}

And create your UI elements (buttons), when they tapped, just trigger related provider;

Just trigger LoginViewModel.startSignInProcess(with: SignInMethod)

AppleSignInButton()
    .frame(height: 50)
    .border(Color.black, width: 1)
    .padding()
    .onTapGesture{ loginViewModel.startSignInProcess(with: .apple) }
    
// Any button that might contain Google's logo and some text
GoogleSignInButton() 
    .frame(height: 50)
    .border(Color.black, width: 1)
    .padding()
    .onTapGesture { loginViewModel.startSignInProcess(with: .google) }

// Any button that might contain Facebook's logo and some text
FacebookSignInButton()
    .frame(height: 50)
    .border(Color.black, width: 1)
    .padding()
    .onTapGesture{ loginViewModel.startSignInProcess(with: .facebook) }

Author

eneskaraosman, [email protected]

License

SocialLogins is available under the MIT license. See the LICENSE file for more info.

sociallogins's People

Contributors

eneskaraosman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ericyangpoxst

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.