Latest 9.4.9
Homepage https://github.com/Cidaas/cidaas-sdk-ios
License MIT
Platforms ios 9.0
Dependencies Alamofire, ReachabilitySwift, CryptoSwift, libCommonCrypto
Authors

More about Cidaas

To know more about Cidaas visit CIDaaS

Cidaas Documentation

https://docs.cidaas.de/

Requirements

Operating System : iOS 9.0 or above
Xcode : 8
Swift : 3.0

Installation

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

pod 'Cidaas-SDK', '~> 8.3'

Getting started

The following steps are to be followed to use this Cidaas-SDK login control

  1. Drag and drop an empty view in the storyboard

  2. Change the name of the class in the properties window as CidaasSDK

  3. Create an IBOutlet for the class and consider this as an object
@IBOutlet weak var cidaasLoginControl: CidaasSDK! 
  1. Create a plist file and fill all the inputs in key value pair. The inputs are below mentioned.

The plist file should become like this :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">
    <dict>
        <key>  AuthorizationURL  </key>
        <string>  Your authorization url  </string>

        <key>  TokenURL  </key>
        <string>  Your token url  </string>

        <key>  UserInfoURL  </key>
        <string>  Your user info url  </string>

        <key>  SocialUrl  </key>
        <string>  your social url  </string>

        <key>  RedirectURI  </key>
        <string>  Your redirect uri  </string>

        <key>  LogoutURL  </key>
        <string>  Your logout url  </string>

        <key>  ClientID  </key>
        <string>  Your client id  </string>

        <key>  ViewType  </key>
        <string>  Your view type  </string>
    </dict>
</plist>
  1. Mention the file name in AppDelegate
CidaasSDK.plistFilename = "Your file name"
  1. Assign the delegate by setting the current view controller as delegate

  2. Call the login() function using the object to get the access token and user information simultaneously
cidaasLoginControl.login { token_response in
// your code here
}  
  1. Call the getUserInfo() function to get the user information by passing access_token as argument
CidaasSDK.getUserInfo(accessToken: "your access token") { user_info_response in
// your code here
}  
  1. Inherit the WKNavigationDelegate and call the methods
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
    cidaasLoginControl.webView(webView, didStartProvisionalNavigation: navigation)
}

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
    cidaasLoginControl.webView(webView, decidePolicyFor: navigationAction, decisionHandler: decisionHandler)
}

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
    cidaasLoginControl.webView(webView, didFinish: navigation)
}

func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
    cidaasLoginControl.webView(webView, didFail: navigation, withError: error)
}
  1. Call the getAccessToken() function to validate the access token by passing user_id as an argument before every service call
CidaasSDK.getAccessToken(userId: "your userId") { token_response in
// your code here
}  
  1. Call the logout() function to logout the session
CidaasSDK.logout(userId: "your userId") { logout_response in
// your code here
}
  1. Call the showUserProfile() function to display the user profile
cidaasLoginControl.showUserProfile(accessToken : "your access token")

            or 

cidaasLoginControl.showUserProfile(userId : "your user id")

It is optional to add your user profile url by calling,

CidaasSDK.user_profile_url = "https://your user profile url"

If you want to integrate with native Facebook and Google SDKs, Add the following lines in AppDelegate.swift

CidaasSDK.facebookSDKEnabled = true
CidaasSDK.googleSDKEnabled = true

In ViewController.swift, create the instance for CidaasFacebook and CidaasGoogle and assign the delegate to current view controller

For more details, refer Cidaas-Facebook and Cidaas-Google

Note

  1. For existing users, to integrate Cidaas-SDK call the updateAccessToken() method for the first time and pass the refresh token as parameter
CidaasSDK.updateAccessToken(refreshToken : "your refresh token" { token_response in
    // your code
})

Steps to add Custom Loaders

  1. Implement the protocol LoaderDelegate in your ViewController.swift

  2. Implement the methods showLoader() and hideLoader()

  3. Inside the methods, write a code to add your custom loader

  4. Assign the loaderDelegate to current ViewController
CidaasSDK.loaderDelegate = self

Steps to find app id and urls

  1. Open the CIDaaS admin UI dashboard page

Dashboard

  1. Move to the Apps menu

Apps

  1. Switch to iOS app tab

iOS App

  1. Press edit button in your app

  2. Note down the app id and app secret for your app

App Id

  1. Move to the OAuth2 endpoints menu

  2. Note down the authorization url, token url, user info url and logout url

End points

Sample Code

ViewController.swift

import UIKit
import Cidaas_SDK
import WebKit

class ViewController: UIViewController, LoaderDelegate, WKNavigationDelegate {

    @IBOutlet var cidaas_sdk: CidaasSDK!
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewWillAppear(_ animated: Bool) {
        login()
    }

    func login() {
        CidaasSDK.loaderDelegate = self
        cidaas_sdk.delegate = self
        cidaas_sdk.login { login_response in

            if login_response.userInfoEntity?.ssoId != nil {
                let page = self.storyboard?.instantiateViewController(withIdentifier: "UserProfileViewController") as!  UserProfileViewController
                page.user_id = login_response.userInfoEntity?.ssoId
                page.access_token = login_response.accessTokenEntity?.accessToken
                self.navigationController?.pushViewController(page, animated: true)
            }
            else {
                let alert = UIAlertController(title: "Information", message: "No user id found", preferredStyle: .alert)
                alert.addAction(UIAlertAction(title: "Done", style: .default, handler: nil))
                self.present(alert, animated: true, completion: {
                    self.login()
                })
            }
        }
    }

    func showLoader() {
        CustomLoader.sharedCustomLoaderInstance.showLoader(self.view, using: nil) { (hud) in

        }
    }

    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
        cidaas_sdk.webView(webView, didStartProvisionalNavigation: navigation)
    }

    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
        cidaas_sdk.webView(webView, decidePolicyFor: navigationAction, decisionHandler: decisionHandler)
    }

    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        cidaas_sdk.webView(webView, didFinish: navigation)
    }

    func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {

    }

    func hideLoader() {
        CustomLoader.sharedCustomLoaderInstance.hideLoader(self.view)
    }
}

UserProfileViewController.swift

import UIKit
import Cidaas_SDK
import WebKit

class UserProfileViewController: UIViewController, LoaderDelegate, WKNavigationDelegate {

    @IBOutlet var cidaas_sdk: CidaasSDK!
    var user_id : String!
    var access_token : String!

    override func viewDidLoad() {
        super.viewDidLoad()
        CidaasSDK.loaderDelegate = self
        cidaas_sdk.delegate = self
        self.navigationItem.setHidesBackButton(true, animated: true)
        cidaas_sdk.showUserProfile(accessToken: access_token)
    }

    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
        cidaas_sdk.webView(webView, decidePolicyFor: navigationAction, decisionHandler: decisionHandler)
    }

    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
        cidaas_sdk.webView(webView, didStartProvisionalNavigation: navigation)
    }

    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        cidaas_sdk.webView(webView, didFinish: navigation)  
    }

    func showLoader() {
        CustomLoader.sharedCustomLoaderInstance.showLoader(self.view, using: nil) { (hud) in

        }
    }

    func hideLoader() {
        CustomLoader.sharedCustomLoaderInstance.hideLoader(self.view)
    }

    @IBAction func backButtonAction(_ sender: Any) {
        self.navigationController?.popViewController(animated: true)
    }

}

Screen shots

Screen 1Screen 2

Note

  1. If you miss any one of the properties or delegate, it will not display anything

Help and Support

For more support visit CIDaaS Support

Latest podspec

{
    "name": "Cidaas-SDK",
    "version": "9.4.9",
    "summary": "Cidaas SDK.",
    "description": "TODO: Add long description of the pod here.",
    "homepage": "https://github.com/Cidaas/cidaas-sdk-ios",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Cidaas": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Cidaas/cidaas-sdk-ios.git",
        "tag": "9.4.9"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "Cidaas-SDK/Classes/**/*",
    "resources": [
        "Cidaas-SDK/Resources/**/*.*",
        "Cidaas-SDK/Assets/*"
    ],
    "dependencies": {
        "Alamofire": [
            "~> 4.6"
        ],
        "ReachabilitySwift": [
            "~> 4.1"
        ],
        "CryptoSwift": [
            "0.7.2"
        ],
        "libCommonCrypto": [
            "0.1.1"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This