GithubHelp home page GithubHelp logo

cidaas / cidaas-sdk-ios-v2 Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 2.0 9.77 MB

With this SDK, you can integrate cidaas smoothly and with minimal effort into your IOS application. It enables you to map the most important user flows for OAuth2 and OIDC compliant authentication. Secure – Fast – And unrivaled Swabian.

Home Page: https://www.cidaas.com

License: MIT License

Ruby 0.25% Swift 99.75%
cidaas ios oauth2 oidc openid-connect

cidaas-sdk-ios-v2's Introduction

Logo

About cidaas:

cidaas is a fast and secure Cloud Identity & Access Management solution that standardises what’s important and simplifies what’s complex.

Feature set includes:

  • Single Sign On (SSO) based on OAuth 2.0, OpenID Connect, SAML 2.0
  • Multi-Factor-Authentication with more than 14 authentication methods, including TOTP and FIDO2
  • Passwordless Authentication
  • Social Login (e.g. Facebook, Google, LinkedIn and more) as well as Enterprise Identity Provider (e.g. SAML or AD)
  • Security in Machine-to-Machine (M2M) and IoT

Cidaas SDK for IOS V2

Platform

The steps here will guide you through setting up and managing authentication and authorization in your apps using cidaas SDK.

Table of Contents

Installation

Swift Package Manager

Open the following menu item in Xcode:

File > Add Packages...

In the Search or Enter Package URL search box enter this URL:

https://github.com/Cidaas/cidaas-sdk-ios-v2

Then, select the dependency rule and press Add Package.

Cocoapods

Add the following line to your Podfile:

pod 'Cidaas'

To use only core functionality and to reduce the size of the dependency

pod 'Cidaas/Core'

Getting started

The following steps are to be followed to use this cidaas SDK.

Create a plist file named Cidaas.plist and fill all the inputs in key value pair. The inputs are mentioned below.

A sample plist file would look 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>DomainURL</key>
        <string>Your Domain URL</string>
        <key>RedirectURL</key>
        <string>Your redirect url</string>
        <key>ClientId</key>
        <string>Your client id</string>
        <key>CidaasVersion</key>
        <string>Your instances major Cidaas Version</string>
    </dict>
</plist>

Migrating to Cidaas V3

Cidaas V3 has response handling adjustment on some of the cidaas service calls. To migrate to cidaas V3, you need to do the following:

  • Ensure that you use at least cidaas version: 3.97.0. You can find the cidaas version from cidaas service portal, and ask our customer service if it needs to be updated.
  • Ensure that you use at least cidaas-ios-sdk version: 1.3.2
  • add CidaasVersion to Cidaas.plist

For Example:

<?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>DomainURL</key>
        <string>Your Domain URL</string>
        <key>RedirectURL</key>
        <string>Your redirect url</string>
        <key>ClientId</key>
        <string>Your client id</string>
        <key>CidaasVersion</key>
        <string>3</string>
    </dict>
</plist>

The following sections will help you to generate some of the information that is needed for plist.

Getting Client Id and urls

When you are integrating your own Business App with, you may want to modularize the interactions and attributes. There are like Scope, Roles, Grant-Types, re-direct URLs etc., that you may want to group into one configuration/settings. This can be done by creating App or Client.

Initialization

The first step to integrate cidaas sdk is the initialization process.

var cidaas = Cidaas();

or use the shared instance

var cidaas = Cidaas.shared

Usage

Native Browser Login

Classic Login

You can login using your native browser and you will be redirected to the App after successful login. To login with your native browser call loginWithBrowser().

var extraParams = Dictionary<String, String>()
extraParams[scopes]="offline_access phone"
cidaas.loginWithBrowser(delegate: self, extraParams: extraParams) {
    switch $0 {
        case .success(let successResponse):
            // your success code here
            break
        case .failure(let error):
            // your failure code here
            break
    }
}

Social Login

You can also perform social login using your native browser and you will be redirected to the App after successful login. To perform social login call loginWithSocial().

cidaas.loginWithSocial(provider: "your_social_provider", delegate: self) { 
    switch $0 {
        case .success(let successResponse):
            // your success code here
            break
        case .failure(let error):
            // your failure code here
            break
    }
}

where social provider may be either facebook, google, linkedin or any other providers

Use customScheme or universalLinks to return back the control from browser to App.

Note : Don't forget to add the custom scheme url in your App's redirect url section

WKWebview integration

Drag and drop an empty view in the storyboard

Change the name of the class in the properties window as CidaasView

Create an IBOutlet for the class and consider this as an object

@IBOutlet var cidaasView: CidaasView! 

Inherit the WKNavigationDelegate and call the methods

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

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

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

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

    Call the loginWithEmbeddedBrowser() function and get the access token as callback    

cidaasView.loginWithEmbeddedBrowser(delegate: self) {
    switch $0 {
        case .success(let successResponse):
            // your success code here
            break
        case .failure(let error):
            // your failure code here
        break
    }
}  

Screenshots

Screen 1 Screen 2

cidaas-sdk-ios-v2's People

Contributors

chandra9990 avatar cidaas-samples avatar ganeshkumargk avatar marvinwidas avatar muthukumarr271 avatar timo-kloss-endava avatar

Stargazers

 avatar  avatar

Watchers

 avatar

cidaas-sdk-ios-v2's Issues

Crash when logged-in users update an app with the new SDK version

If a user logged in with an app using the old Cidaas SDK and then update to a version with the new Cidaas SDK, it will crash.

The problem is the function accessTokenModelToAccessTokenEntity:

One line was was changed from:
AccessTokenModel.shared.refresh_token = accessTokenEntity.refresh_token
to:
AccessTokenModel.shared.refresh_token = try! accessTokenEntity.refresh_token.aesEncrypt(key: key, iv: salt)

There is no fallback for old user data without encryption, and there is no error handling either. It just crashes.

The same seems to be true for access_token

Refresh token still encrypted when sending to API

The token refresh is broken, because "accessTokenModel.refresh_token" is still encrypted when using in "self.getAccessToken(refreshToken: ..."
It's only uncoded in "accessTokenModelToAccessTokenEntity"

`
public func getAccessToken(sub: String, callback: @escaping (Result) -> Void) {

    // getting current seconds
    let milliseconds = Date().timeIntervalSince1970
    let seconds = Int64(milliseconds)
    
    let accessTokenModel = DBHelper.shared.getAccessToken(key: sub)
    let expires = accessTokenModel.expires_in
    let secs: Int64 = Int64(accessTokenModel.seconds)
    let expires_in = expires + secs - 10
    
    if expires_in > seconds {
        
        if String(seconds).count < 10 {
            self.getAccessToken(refreshToken: accessTokenModel.refresh_token, callback: callback)
            return
        }
        
        EntityToModelConverter.shared.accessTokenModelToAccessTokenEntity(accessTokenModel: accessTokenModel) { (accessTokenEntity) in
            // return success callback
            let response = LoginResponseEntity()
            response.success = true
            response.status = 200
            response.data = accessTokenEntity
            
            DispatchQueue.main.async {
                callback(Result.success(result: response))
            }
            return
        }
    }
        
    else {
        self.getAccessToken(refreshToken: accessTokenModel.refresh_token, callback: callback)
    }
}

`

Wrong charset: Error with special characters for example in getUserInfo

The Cidaas API returns data in utf8, which is good, but it doesn't specify this in the response headers. The default parser in the SDK (in Alamofire) is some old ISO standard, so utf8 strings with special characters are parsed incorrectly.
At least the SDK should set the correct encoding. Even better would be, if the API sent the charset in its response headers.

Support SwiftUI

I'm attempting to integrate your SDK with SwiftUI and have encountered challenges with web view integration. As per my observations, instantiating a CidaasView without utilizing a storyboard seems to be problematic.

Could you kindly furnish a solution or guidelines for SwiftUI compatibility?

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.