More about Cidaas
To know more about Cidaas visit CIDaaS
Cidaas Documentation
Requirements
Operating System : iOS 10.0 or above
Xcode : 9
Swift : 4.0
Installation
Cidaas-SDK is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Cidaas-SDK', '~> 10.0'
Getting started
The following steps are to be followed to use this Cidaas-SDK login control
- 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>
- Mention the file name in AppDelegate
CidaasSDK.plistFilename = "Your file name"
Getting app id and urls
You will get the property file for your application from the cidaas AdminUI
There are 2 ways of Cidaas-SDK integration
-
Native browser integration - Opens Safari browser to login. Not supporting native Facebook and Google SDK
-
WKWebview integration - Opens webview to login. Additionally supports native Facebook and Google SDK
Native Browser integration
- Create an instance of CidaasSDK
var cidaas = CidaasSDK()
(or)
var cidaas = CidaasSDK.shared
- Assign the safariDelegate to current view controller
cidaas.safariDelegate = self
- call the loginWithNativeBrowser() method and get the access token and user information as callback
cidaas.loginWithNativeBrowser { (token_response) in
// your code
}
- Call the showUserProfileInBrowser() function to display the user profile
cidaas.showUserProfileInBrowser(accessToken : "your access token")
or
cidaas.showUserProfileInBrowser(userId : "your user id")
It is optional to add your user profile url by calling,
CidaasSDK.user_profile_url = "https://your user profile url"
Use customScheme or universalLinks as redirectURL which is mandatory.
- If you use custom scheme, configure your URL types and resume the SDK from AppDelegate's open url method
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
CidaasSDK.shared.resume(open: url)
return true
}
- If you use universal links, configure your Domain setup and resume the SDK from AppDelegate's userActivity method
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
let url = userActivity.webpageURL!
CidaasSDK.shared.resume(open: url)
return true
}
WKWebview integration
-
Drag and drop an empty view in the storyboard
-
Change the name of the class in the properties window as CidaasSDK
-
Create an IBOutlet for the class and consider this as an object
@IBOutlet weak var cidaas : CidaasSDK!
- Inherit the WKNavigationDelegate and call the methods
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
cidaas.webView(webView, didStartProvisionalNavigation: navigation)
}
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
cidaas.webView(webView, decidePolicyFor: navigationAction, decisionHandler: decisionHandler)
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
cidaas.webView(webView, didFinish: navigation)
}
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
cidaas.webView(webView, didFail: navigation, withError: error)
}
- Assign the delegate by setting the current view controller as delegate
cidaas.delegate = self
- Call the login() function and get the access token and user information as callback
cidaas.login { token_response in
// your code here
}
- Call the showUserProfile() function to display the user profile
cidaas.showUserProfile(accessToken : "your access token")
or
cidaas.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"
Common functions
- 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
}
- Call the getAccessToken() function to validate the access token by passing user_id as an argument
CidaasSDK.getAccessToken(userId: "your userId") { token_response in
// your code here
}
- Call the logout() function to logout the session
CidaasSDK.logout(userId: "your userId") { logout_response in
// your code here
}
- If you want to integrate with native Facebook and Google SDKs, Add the following lines in AppDelegate.swift
CidaasSDK.enableNativeFacebook = true
CidaasSDK.enableNativeGoogle = true
- Call the getAccessTokenSync() function to get the access token by passing refresh_token, user_id as an argument (For synchronous purpose only.)
CidaasSDK.getAccessTokenSync(refreshToken: (callbackEntity.accessTokenEntity?.refreshToken)!, userId: (callbackEntity.userInfoEntity?.ssoId)!, callback: { (resp) in
// your code here
})
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 : Native Facebook and Native Google SDK supportability is only for WKWebview integration
Steps to add Custom Loaders
-
Implement the protocol LoaderDelegate in your ViewController.swift
-
Implement the methods showLoader() and hideLoader()
-
Inside the methods, write a code to add your custom loader
-
Assign the loaderDelegate to current ViewController
CidaasSDK.loaderDelegate = self
Sample Code
ViewController.swift
import UIKit
class ViewController: UIViewController {
var cidaas_sdk : CidaasSDK = CidaasSDK.shared
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func openBrowser(_ sender: Any) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "NativeBrowserViewController") as! NativeBrowserViewController
self.navigationController?.pushViewController(vc, animated: true)
}
@IBAction func openWebView(_ sender: Any) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "WKViewController") as! WKViewController
self.navigationController?.pushViewController(vc, animated: true)
}
}
NativeBrowserViewController.swift
import UIKit
import Cidaas_SDK
class NativeBrowserViewController: UIViewController, LoaderDelegate {
var cidaas_sdk : CidaasSDK = CidaasSDK.shared
var visible : Bool = false
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
if visible == false {
visible = true
CidaasSDK.loaderDelegate = self
loginWithNativeBrowser()
}
}
func loginWithNativeBrowser() {
cidaas_sdk.safariDelegate = self
cidaas_sdk.loginWithNativeBrowser { (callbackEntity) in
let alert = UIAlertController(title: "Access Token", message: "\(callbackEntity.accessTokenEntity?.accessToken ?? "")", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Done", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func showLoader() {
CustomLoader.sharedCustomLoaderInstance.showLoader(self.view, using: nil) { (hud) in
}
}
func hideLoader() {
CustomLoader.sharedCustomLoaderInstance.hideLoader(self.view)
}
@IBAction func backPressed(_ sender: Any) {
self.navigationController?.popViewController(animated: true)
}
}
WKViewController.swift
import UIKit
import WebKit
import Cidaas_SDK
class WKViewController: UIViewController, WKNavigationDelegate, LoaderDelegate {
@IBOutlet var cidaas_sdk: CidaasSDK!
override func viewDidLoad() {
super.viewDidLoad()
CidaasSDK.loaderDelegate = self
login()
}
func login() {
cidaas_sdk.delegate = self
cidaas_sdk.login { (callbackEntity) in
let alert = UIAlertController(title: "Access Token", message: "\(callbackEntity.accessTokenEntity?.accessToken ?? "")", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Done", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
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) {
cidaas_sdk.webView(webView, didFail: navigation, withError: error)
}
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
cidaas_sdk.webView(webView, didFail: navigation, withError: error)
}
func hideLoader() {
CustomLoader.sharedCustomLoaderInstance.hideLoader(self.view)
}
@IBAction func backPressed(_ sender: Any) {
self.navigationController?.popViewController(animated: true)
}
}
AppDelegate.swift
import UIKit
import Cidaas_SDK
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
CidaasSDK.plistFilename = "CidaasURLProperty"
return true
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
let url = userActivity.webpageURL!
CidaasSDK.shared.resume(open: url)
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
CidaasSDK.shared.resume(open: url)
return true
}
func applicationWillResignActive(_ application: UIApplication) {
}
func applicationDidEnterBackground(_ application: UIApplication) {
}
func applicationWillEnterForeground(_ application: UIApplication) {
}
func applicationDidBecomeActive(_ application: UIApplication) {
}
func applicationWillTerminate(_ application: UIApplication) {
}
}
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
Note
- If you miss any one of the properties or delegate, it will not display anything
Help and Support
For more support visit CIDaaS Support