SDKs & Sample Apps
SDKs
AAA SDK
17min
authentication and authorization (aaa) sdk for web the aaa sdk for web is built on top of react, oidc react, and typescript this sdk can be used for authentication, maintaining access tokens, fetching user info, and appending headers to the rest api calls to learn more about aaa, see authentication and authorization docid\ d6naiubkxdnzeyhfv5gtq installation install @os1 platform/aaa web into your project npm install @os1 platform/aaa web peer dependencies the aaa sdk has the following peer dependencies { "axios" ">=0 24 2", "react" "^17 0 2" } usage use the initcas api of the sdk to create auth instance and fetch the authprovider component import { initcas } from '@os1 platform/aaa web'; const authprovider = initcas( 'clientid', // this is the clientid that you get after creating an app '/fms/success', // success pathname (https //abc fxtrt io/fms/success) 'web', // device type '/fms/failure', //logoutredirectpath 'tenantidfordevelopmentmode' //static tenantid for development mode to test any functionality locally (accepted if the sub domain is developer or developer2)(optional field) ); wrap your application in this single authprovider component for example reactdom render( \<react strictmode> \<browserrouter basename="/fms"> \<authprovider> \<router /> \</authprovider> \</browserrouter> \</react strictmode>, document getelementbyid('root') ); or reactdom render( \<authprovider> \<app /> \</authprovider>, document getelementbyid('root') ); pass the loader component to the authprovider to override the default loader import loader from 'your loader component'; \<authprovider loader={\<loader />}>{children}\</authprovider>; use the loginwithredirect method to initiate login import { loginwithredirect } from '@os1 platform/aaa web'; \<button onclick={() => loginwithredirect()}>login\</button>; use the isauthenticated method to put a check on private pages\ this checks if the user has valid permissions to access private pages that require access via token, unlike public pages like the 'contact us' page import { isauthenticated } from '@os1 platform/aaa web'; const isauth = isauthenticated(); use the getaccesstokensilently method, to fetch the access token import { getaccesstokensilently } from '@os1 platform/aaa web'; const token = await getaccesstokensilently(); use the getuserinfo method, to fetch user info import { getuserinfo } from '@os1 platform/aaa web'; const userinfo = await getuserinfo(); use the httpclient api to create a client for network requests import { httpclient as client } from '@os1 platform/aaa web'; class networkclient { public readonly instance any; constructor() { this instance = client createclient({ baseurl `https //abc preprod fxtrt io/core/api/v1/aaa`, }); } } the following headers are automatically configured to requests originating from the networkclient adding access token( x coreos access ) or the tenant id( x coreos tid ) or user info( x coreos userinfo ) or auth token( x coreos auth ) headers to the actual request withaccess withtid withuserinfo withauth note by default all these headers are true, i e , will be passed to the rest api the user needs to specifically pass value against these headers as false if they don't wish to pass certain headers access token is verified and regenerated (if expired), every time an api request is made x coreos userinfo contains the userid x coreos auth contains the id token import networkclient from ' /networkclient'; const handleclick = () => { const client1 = new client(); const reqheaders any = { withaccess false, withtid false, withuserinfo false, withauth false, }; client1 instance get('/users', { headers { 'x coreos request id' '1d8cb10a 02c0 4fb9 b5e3 d4d432717c49', reqheaders, }, }) catch((err) => { console log(err); // error handling code here }); }; use the logout method, to implement logout functionality import { logout } from '@os1 platform/aaa web'; await logout(); authentication and authorization (aaa) sdk for mobile the aaa (authentication and authorization) sdk for mobile is used for authentication purposes to integrate with the front end applications this sdk is built on top of react native, react native app auth, and typescript you can use this sdk on mobile for authentication, fetching access tokens, and logout features to learn more about aaa, see aaa documentation installation install @os1 platform/aaa mobile into your project yarn add @os1 platform/aaa mobile install peer dependencies yarn add react native app auth\@6 4 3 yarn add @react native async storage/async storage@^1 15 14 yarn add axios@^0 26 1 add manifest placeholder in build gradle (app level) manifestplaceholders = \[appauthredirectscheme "${applicationid}"] usage init aaa sdk initauth0 initiates the authentication process and creates an instance of auth // obtain domain and clientid from auth0/ keycloak dashboard import { loginhelper } from '@os1 platform/aaa mobile'; await loginhelper initauth0( 'domain', 'clientid' ); example await loginhelper initauth0( 'example dev io', 'some rn app' ) initiate login initlogin() uses the auth instance and opens the web page on mobile containing the os1 login page import { loginhelper } from '@os1 platform/aaa mobile'; // pass keys name for storing access token and id token await loginhelper initlogin('token', 'idtoken') then((res any) => { console log('result ', res); }); // result type export interface authorizeresult { accesstoken string; accesstokenexpirationdate string; authorizeadditionalparameters? { \[name string] string }; tokenadditionalparameters? { \[name string] string }; idtoken string; refreshtoken string; tokentype string; scopes string\[]; authorizationcode string; codeverifier? string; } logout import { loginhelper } from '@os1 platform/aaa mobile'; await loginhelper logoutuser('token'); fetch access token import { loginhelper } from '@os1 platform/aaa mobile'; const accesstoken = await loginhelper fetchaccesstoken(); //this will fetch the latest access token from the storage and if the token is expired then it calls refresh token internally and returns the new access token refresh token import { loginhelper } from '@os1 platform/aaa mobile'; await loginhelper refreshtoken();