Latest 1.0
Homepage https://github.com/Thywis/MultiAccountOauth
License Apache License, Version 2.0 Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Platforms ios 9.0, requires ARC
Dependencies AppAuth, SwiftyJSON, Alamofire
Authors

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

Latest podspec

{
    "name": "MultiAccountOAuth",
    "version": "1.0",
    "summary": "Login to multiple Google OAuth accounts simultaneouly.",
    "platforms": {
        "ios": "9.0"
    },
    "description": "While developing [PickedMail - The personal AI Inbox](https://itunes.apple.com/us/app/pickedmail/id1244830423?mt=8), 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.",
    "homepage": "https://github.com/Thywis/MultiAccountOauth",
    "license": {
        "type": "Apache License, Version 2.0",
        "text": "Licensed under the Apache License, Version 2.0 (the "License");nyou may not use this file except in compliance with the License.nYou may obtain a copy of the License atnnhttp://www.apache.org/licenses/LICENSE-2.0nnUnless required by applicable law or agreed to in writing, softwarendistributed under the License is distributed on an "AS IS" BASIS,nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.nSee the License for the specific language governing permissions andnlimitations under the License.n"
    },
    "authors": {
        "likedan": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Thywis/MultiAccountOauth.git",
        "tag": "1.0.0"
    },
    "social_media_url": "https://itunes.apple.com/us/app/pickedmail/id1244830423?mt=8",
    "requires_arc": true,
    "dependencies": {
        "AppAuth": [
            "~> 0.9.1"
        ],
        "SwiftyJSON": [
            "~> 3.1.4"
        ],
        "Alamofire": [
            "~> 4.5.0"
        ]
    },
    "source_files": "MultiAccountOauth/*.swift",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This