Xamarin iOS SDK

The following things are to be kept in mind while integrate our cidaas sdk

Configuring App/Client:

When you are integrating your own Business App with cidaas, you may want to modularize the interactions and attributes. There are several information 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 cidaas App or Client.

The steps here will guide you through set up and management of authentication and authorization in your apps using cidaas Xamarin iOS SDK.

Click here for Sample Project.

Requirements

Visual Studio           :   2017
Operating System        :   iOS 10 or above

Installation

cidaas-sdk-ios-v2 is available through NuGet. There are 3 options to integrate it in your project

1 . Enter the following command in Package Manager Console

`Install-Package cidaas-sdk-ios-v2`

2 . Download the package from the following url

`https://www.nuget.org/packages/cidaas-sdk-ios-v2`

3 . Once downloaded, drag and drop the file to your project

Right click on your project and select Add Nuget Packages option. Search for cidaas-sdk-ios-v2 and install it

Getting Started

Create a new plist file and add the following code

<?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>  RedirectURI  </key>
        <string>  Your redirect uri  </string>

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

    </dict>
</plist>

2 . Add the file name of the plist in your AppDelegate.cs file

CidaasSDKView.CIDAAS_PLIST_FILE_NAME = "Cidaas";

Login

3 . To perform login operation create a view in your Xib and named as cidaasView copy and paste the below code snippet in your cs file

var cidaas = CidaasSDKView.Create();
cidaas.Frame = View.Frame;
cidaas.Login();
cidaas.OnLoginSuccess += (sender, response) =>
{
    // your succes code here
    // UserInfoEntity userInfoEntity = response.UserInfoEntity;
    // TokenEntity tokenEntity = response.TokenEntity;
};
cidaas.OnProcess += (sender, response) =>
{
    // Use this block to show or hide loader while login process going on
    // Boolean isLoading = response.loading
};
cidaasView.AddSubview(v);

Getting User Information

4 . To get user information, call GetUserInfoByAccessToken() method

CidaasSDKView.GetUserInfoByAccessToken(access_token);

Getting Access token

5 . To validate access token, call GetAccessToken() method

CidaasSDKView.GetAccessToken(user_id);

Logout user

6 . To logout the session, call Logout() method

CidaasSDKView.Logout(user_id);

Get Login URL

7 . To get login URL, call GetLoginURL() method

var loginURL = CidaasSDKView.GetLoginURL();

Get Register URL

8 . To get register URL, call GetRegisterURL() method

var registerURL = CidaasSDKView.GetRegisterURL();

Token Validation Check

9 . To check whether the token is valid or not, call validateToken() method

bool tokenCheck = CidaasSDKView.validateToken(access_token);

Sample Code

ViewController.cs


using System;

using UIKit;
using Foundation;
using CidaasSDKiOS;
using CidaasSDK.Helpers;
using CidaasSDKiOS.Helpers;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Net.Http;
using CidaasSDK.Entity;
using CidaasSDKiOS.Entity;

namespace iOSExampleXamarin
{
    public partial class ViewController : UIViewController
    {
        private string user_id;
        private string access_token;

        protected ViewController(IntPtr handle) : base(handle)
        {
            // Note: this .ctor should not contain any initialization logic.
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            createView();
        }

        private void createView()
        {

            var loginURL = CidaasSDKView.GetLoginURL();
            var registerURL = CidaasSDKView.GetRegisterURL();

            var v = CidaasSDKView.Create();
            v.Frame = View.Frame;
            v.Login();
            v.OnLoginSuccess += (sender, e) =>
            {
                user_id = e.UserInfoEntity.sub;
                access_token = e.TokenEntity.access_token;
                var tokenCheck = CidaasSDKView.validateToken(access_token);

            };
            v.OnProcess += (sender, e) =>
            {
                if (e.Loading == true) {
                    CidaasLoader.ShowLoader();
                }
                else {
                    CidaasLoader.HideLoader();
                }
            };
            cidaasView.AddSubview(v);
        }

        public override void DidReceiveMemoryWarning()
        {
            base.DidReceiveMemoryWarning();
            // Release any cached data, images, etc that aren't in use.
        }
    }
}



results matching ""

    No results matching ""