1.0.6 • Published 3 years ago
@os1-platform/aaa-mobile v1.0.6
React native AAA mobile SDK
Introduction
Built on top of react-native, react-native-app-auth, typescript. This sdk can be used on mobile for authentication, to fetch access token and logout feature.
Installation
npm install @os1-platform/aaa-mobileInstall Peer dependencies
npm install react-native-app-auth@6.4.3
npm install @react-native-async-storage/async-storage@^1.15.14
npm install axios@^0.26.1Peer dependencies:
{
"@react-native-async-storage/async-storage": "^1.15.14",
"react": ">=17.0.2",
"react-native": ">=0.67.3",
"react-native-app-auth": "^6.4.3",
"axios": ">=0.26.1"
}Add Manifest Placeholder in build.gradle (app level)
manifestPlaceholders = [appAuthRedirectScheme: "${applicationId}"]Usage
Init AAA SDK
// Obtain domainId and clientId from Auth0/ Keycloak dashboard
import { LoginHelper } from '@os1-platform/aaa-mobile';
await LoginHelper.initAuth0(
'domain', //example.dev.io
'clientId' //some-rn-app
);
//Note : domainId should start with https://Initiate Login
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 tokenRefresh Token
import { LoginHelper } from '@os1-platform/aaa-mobile';
await LoginHelper.refreshToken();