GithubHelp home page GithubHelp logo

thywis / multiaccountoauth Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 4.0 429 KB

Login to multiple Google OAuth2 accounts simultaneously on iOS

License: MIT License

Ruby 11.51% Swift 88.49%
ios swift3 googleapi google-api googleoauth oauth2 google

multiaccountoauth's Introduction

MultiAccountOAuth

MultiAccountOAuth allows you to login to multiple Google OAuth accounts simultaneouly.

While developing PickedMail - The personal AI Inbox, we need to support user login to multiple Google accounts simultaneously. However, Google iOS SDK only allows user to sign in to one account at a time. As a result, we developed a framework to allow us to sign in and maintain connection status to multiple Google accounts. This framework is open sourced to help others who struggling through the same problem.

Install

pod 'MultiAccountOAuth'

Requirements

  • Swift 3.0+
  • Xcode 8.0+
  • iOS 9.0+, OSX 10.10+

Usage

Login to an Google Account

public func signin(controller: UIViewController, completion: ((_ success: Bool, _ user: GoogleUserInstance?, _ error: String?) -> ())?)

Login to multiple Google accounts

public func signin(controller: UIViewController, completion: ((_ success: Bool, _ user: GoogleUserInstance?, _ error: String?) -> ())?)

Get access to all of them

public var authenticatedUsers = [GoogleUserInstance]()

Next time when the user launches the app, sign in to all the Google accounts from background.

public func signinAllUsersSilently(completion: @escaping ()->() = {})

Step by Step Setup Guide

1. Google Credential

  • Create an iOS Applicaiton in Google API Console. Make sure you have the correct client id and URL scheme.

  • Go to Info.plist in your iOS application, add the URL scheme to URL types.

2. AppDelegate.swift

Configure the google client id and URL scheme. You can optionally provide a server client id if you'd like to enable backend sever access.

import UIKit
import MultiAccountOAuth

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

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

        OauthManager.sharedInstance.configure(cliendId: "269767058620-boug6i0q16vsh7a90cf7341skc1j91sj.apps.googleusercontent.com", scope: ["email"], urlScheme: "com.googleusercontent.apps.269767058620-boug6i0q16vsh7a90cf7341skc1j91sj", serverCliendId: nil)

        return true
    }

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        if let oauthSession = OauthManager.sharedInstance.oauthSession {
            if oauthSession.resumeAuthorizationFlow(with: url) {
                OauthManager.sharedInstance.oauthSession = nil
                return true
            }
        }
        return false
    }
}

The list of Google Scopes to choose from

multiaccountoauth's People

Contributors

likedan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.