Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

exozet/cidaas-android-sdk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 Android SDK

Build Status codecov.io jitpack Platform

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

About cidaas:

cidaas is a fast and secure Cloud Identity & Access Management solution that standardises what’s important and simplifies what’s complex. The cidaas 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

Note:

This SDK was renamed from cidaas -v2-sdk-android to cidaas-android-sdk. To migrate from the older version <2.1.0, please refer to the Migration guide

Table of Contents

Requirements

minSdkVersion 21

Steps to integrate the native android SDK:

Installation

The cidaas SDK is available through jitpack.io.
Please ensure that you are using the latest version by checking here

Add the following Gradle configuration to your Android project:

allprojects {
    repositories {
        ...
		maven { url 'https://jitpack.io' }
	}
}

Add the dependency to app module

dependencies {
implementation 'com.github.Cidaas:cidaas-android-sdk:3.0.0'
}

This will add all the subproject of cidaas SDK, if you only need a specific subproject for your use case, just add it's name before the version. E.g.:

dependencies {
   implementation 'com.github.Cidaas:cidaas-android-sdk:cidaasnative:3.0.0'
}

This will then add only the features available under cidaasnative.

For now we need to implement only cidaas core Functions

So please Add

dependencies {
   implementation 'com.github.Cidaas:cidaas-android-sdk:cidaas:3.0.0'
}
Note:- This Library is developed in AndroidX so AndroidX migration is necessary

To migrate your project into Androidx in android studio goto

Refactor-> Migrate to AndroidX

Getting started

Create an asset folder by right clicking the app module. Go to new -> folder -> Assets folder and click the finish button

Create an xml file named cidaas.xml inside the asset folder and fill all the inputs for the key value pairs. The inputs are below mentioned.

Note:- The File name must be cidaas.xml

A sample XML file would look like this :

<?xml version="1.0" encoding="utf-8"?>
<resources>
	<item name="DomainURL" type="string">DomainURL</item>
	<item name="ClientId" type="string">ClientId</item>
	<item name="RedirectURL">RedirectURL</item>
</resources> 

Following sections will help you to generate some of the information that is needed for XML.

Getting client Id and urls

You can get this by creating your app in the app settings section of the cidaas admin portal. Once you have selected the right scope and application type, and have filled in all of the mandatory fields, you can use the generated client id and re-direct URLs.

Initialisation

The first step of integrating the cidaas sdk is the initialisation process:

Cidaas cidaas = Cidaas.getInstance(yourActivityContext);

    or

Cidaas cidaas =new Cidaas(yourActivityContext);

Usage

Note:- If you are going to use the native browser login, you must use the getInstance() method to create a new instance of the cidaas SDK

Native Browser Login

Classic Login

You can login using your native browser and redirect back to the App once you have successfully logged in. To login with your native browser call loginWithBrowser().

cidaas.loginWithBrowser(yourActivityContext, "NullableColorParameterInColorCode", new EventResult<AccessTokenEntity>() {
     @Override
     public void success(AccessTokenEntity result) {
    	//Your Success Code
     }

     @Override
     public void failure(WebAuthError error) {
		//Your Failure Code
     }
});

Add a deep link or app link (#add-custom-scheme)

You can get the url for the login by calling getLoginURL() and load your favorite browser like this:

Cidaas.getInstance(yourContext).getLoginURL(new EventResult<String>() {
    @Override
    public void success(String result) {
        //Your Success code
    }

    @Override
    public void failure(WebAuthError error) {
        //Your Failure code
    }
});

Social Login

You can also perform social login using your native browser and redirect back to the app once the login was successful. To perform a social login call loginWithSocial().

cidaas.loginWithSocial(yourActivityContext, "requestID", your_Social_Provider, "Nullable_Color_Parameter_In_Color_Code", new EventResult<AccessTokenEntity>() {
    @Override
    public void success(AccessTokenEntity result) {
        //Your Success Code
    }

    @Override
    public void failure(WebAuthError error) {
		//Your Failure Code
    }
 });

where social provider may be either "facebook", "google", "linkedin" or any other providers which are configured for your app via the cidaas admin dashboard.

To get the url for the social login and load it in your favorite browser you can call

Cidaas.getInstance(yourContext).getSocialLoginURL(yourRequestid,your_social_provider,new EventResult<String>() {
    @Override
    public void success(String result) {
       //Your Success Code
    }

    @Override
    public void failure(WebAuthError error) {
       	//Your Failure Code
    }
});

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

Register in Browser

To register with the browser, you can call the following method

Cidaas.getInstance(yourContext).RegisterWithBrowser(youraAtivityContext, "Nullable_Color_Parameter_In_Color_Code", new EventResult<AccessTokenEntity>() {
    @Override
    public void success(AccessTokenEntity result) {
         //Your Success Code
    }

    @Override
    public void failure(WebAuthError error) {
    	//Your Failure Code
    }
});

To get the url for the registration and load it in your favorite browser you can call

Cidaas.getInstance(yourContext).getRegistrationURL(new EventResult<String>() {
    @Override
    public void success(String result) {
         //Your Success Code
    }

    @Override
    public void failure(WebAuthError error) {
          //Your Failure Code
    }
});

Logout

To use logout, You can call following functions

    CidaasNative.getInstance(this).logout("AccessToken", new EventResult<Boolean>() {
            @Override
            public void success(Boolean result) {
                 //Your Success Code
            }

            @Override
            public void failure(WebAuthError error) {
                //Your Failure Code
            }
        });

Add a custom scheme

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

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

If you use a deep link or custom scheme, After adding the intent-filter in the manifest file, add android:launchMode="singleTop" in the activity you redirected. For example if you redirect your link from browser to mainactivity

 <activity android:name=".MainActivity" android:launchMode="singleTop">

and resume the SDK from your activity

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        String token = intent.getDataString();
        if (token != null) {
            cidaas.handleToken(token);
            
        } else {
           //your else part
        }
    }

}

If you use app links, configure your Domain setup and resume the SDK from your activity

  @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        String token = intent.getDataString();
        if (token != null) {
            cidaas.handleToken(token);
            
        } else {
           //your else part
        }
    }
}

Common Methods

Getting AccessToken

You can get the access token for the current user using the following call

cidaas.getAccessToken(yourSub, new EventResult<AccessTokenEntity>() {
 @Override
 public void success(AccessTokenEntity result) {
      //Your Success Code
  }

  @Override
  public void failure(WebAuthError error) {
       //Your Failure Code
   }
  }); 

By default the access token is renewed when you call the getAccessTokenMethod, if you want to renew the token manually you need to call the following method

cidaas.getAccessTokenFromRefreshToken(refreshToken, new EventResult<AccessTokenEntity>() {
   @Override
   public void success(AccessTokenEntity result) {
      // Your Success Code                
   }

   @Override
   public void failure(WebAuthError error) {
      // Your Failure Code
    }
  });
        
Enable PKCE flow

By default the PKCE flow is enabled. If you want to disable the PKCE flow, you can call the following method

Cidaas.getInstance(yourContext).setENABLE_PKCE(false);
Note:- If you disable the PKCE flow, you must use add the 'ClientSecret' variable in your cidaas.xml:
<item name="ClientId" type="string">ClientId</item>

To know whether the PKCE is enabled or not, use the following method

Cidaas.getInstance(yourContext).isENABLE_PKCE();

it will return a boolean value which is true if PKCE is enabled and false if it is disabled.

Enable Log

By default the logger is disabled. If you want to enable the logger, you can call the following method

Cidaas.getInstance(yourContext).enableLog();
      

To disable the Log

Cidaas.getInstance(yourContext).disableLog();
      

To know whether the Log is enabled or not, use the following method

Cidaas.getInstance(yourContext).isLogEnable();

It will return a boolean value, which is true if the logger is enabled for the SDK and false if it is disabled.

User information
Cidaas.getInstance(yourContext).getUserInfo("yourSub", new EventResult<UserinfoEntity>() {
 @Override
   public void success(UserinfoEntity result) {
      //Your Success Code
     }

 @Override
  public void failure(WebAuthError error) {
      //Your Failure code
     }
});

Embedded Browser Login

You can use the embedded browser to login with cidaas. For this do the following steps:

  1. You have to add '< uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>' in your manifest file.
  2. Create an instance of the CidaasSDKLayout using the activity context.
  CidaasSDKLayout cidaasSDKLayout = CidaasSDKLayout.getInstance(this);
  
     or
  
  CidaasSDKLayout cidaasSDKLayout = new CidaasSDKLayout(this);

3.Call loginWithEmbeddedBrowser() .

4.Pass the relative layout as argument

 RelativeLayout relativeLayout=findViewById(R.id.relative_layout_for_webView);
 
 cidaasSDKLayout.loginWithEmbeddedBrowser(relativeLayout, new EventResult<AccessTokenEntity>() {
 @Override
 public void success(AccessTokenEntity result) {
      //Your Success Code
  }

  @Override
  public void failure(WebAuthError error) {
       //Your Failure Code
   }
  }); 
Get Access Token From social

If your app has received an access token from google or facebook, then you can use following method to get the access token of cidaas.

SocialAccessTokenEntity socialAccessTokenEntity = new SocialAccessTokenEntity();
socialAccessTokenEntity.setToken(yourtoken);
socialAccessTokenEntity.setDomainURL(yourDomainURL);
socialAccessTokenEntity.setProvider(yourprovider);
socialAccessTokenEntity.setViewType(yourviewType);

Cidaas.getInstance(yourActivityContext).getAccessTokenBySocial(socialAccessTokenEntity, new EventResult<AccessTokenEntity>() {
    @Override
    public void success(AccessTokenEntity result) {
        //Your Success Code
    }

    @Override
    public void failure(WebAuthError error) {
       //Your Failure code
    }
 });

here yourviewType is "login" and provider is "google" or "facebook"

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%