cidaas-cordova-sdk
v1.0.2
Published
cidaas cordova sdk for mobile applications
Downloads
5
Readme
cidaas-cordova-sdk
The steps here will guide you through setting up and managing authentication and authorization in your apps using cidaas cordova SDK.
Table of Contents
Installation
Cidaas cordova sdk is available through npm.
npm install cidaas-cordova-sdk
npm install cordova-plugin-inappbrowser
Getting started
The following steps are to be followed to use this cidaas SDK.
var options = {
authority: 'your domain base url',
client_id: 'your app id',
redirect_uri: 'your redirect url',
response_type: 'id_token token',
scope: 'openid email roles profile'
}
var web = new CidaasCordovaSDK.WebAuth(options);
The following sections will help you to generate some of the information that is needed for the options.
Getting Client Id and urls
You can get this by creating your App in App settings section of cidaas Admin portal. Once you select the right scope and application type, and fill in all mandatory fields, you can use the generated Client ID and redirect URLs.
Usage
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().
Sample Code
web.loginWithBrowser(options, function (data) {
// your code
});
Response
{
"success": true,
"status": 200,
"data": {
"token_type": "Bearer",
"expires_in": 86400,
"access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjUxNWYxMGE5LTV",
"session_state": "CNT7TF6Og-cCNq4Y68",
"refresh_token": "jahsdujagsudyasasdfsdf",
"viewtype": "login",
"grant_type": "login"
}
}
Note : please refer InAppBrowser_options for more details
Getting user profile
You can get user profile by calling getUserInfo().
Sample Code
web.getUserInfo({
access_token: 'your access_token'
}).then(function (data) {
// your success code
}).catch(function (ex) {
// your failure code
});
Response
{
"sub": "cc28a557-ce0d-4896-9580-49639cbde8d5",
"email": "[email protected]",
"email_verified": true,
"name": "David Jhonson",
"family_name": "Jhonson",
"given_name": "David",
"nickname": "test",
"preferred_username": "davidjhonson",
"gender": "Male",
"locale": "en-us",
"updated_at": 1527662349,
"username": "davidjhonson"
}
Validate token
You can validate the token by calling validateAccessToken().
Sample Code
web.validateAccessToken({
token: 'your token',
token_type_hint: 'access_token'
}).then(function (data) {
// your success code
}).catch(function (ex) {
// your failure code
});
Response
{
"active": true
}
Renew token
You can renew your token by calling renewToken().
Sample Code
web.renewToken({
refresh_token: 'your refresh_token'
}).then(function (data) {
// your success code
}).catch(function (ex) {
// your failure code
});
Response
{
"success": true,
"status": 200,
"data": {
"token_type": "Bearer",
"expires_in": 86400,
"access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjUxNWYxMGE5LTV",
"session_state": "CNT7TF6Og-cCNq4Y68",
"refresh_token": "jahsdujagsudyasasdfsdf",
"viewtype": "login",
"grant_type": "login"
}
}
Logout
To logout the session, call logout().
Sample Code
web.logout(access_token, options, function (data) {
// your success code
});
or simply call,
web.logout(access_token);