@vatom/identity-sdk
v0.0.16
Published
This library allows you to embed and use the Vatom™ Identity system to authenticate your users within your web app.
Downloads
46
Keywords
Readme
Vatom™ Identity SDK
This library allows you to embed and use the Vatom™ Identity system to authenticate your users within your web app.
Installation
You can install this library by running npm install @vatom/identity-sdk
or yarn add @vatom/identity-sdk
Basic Usage
In order to seamlessly integrate with your own identity system you would need to first obtain an authority and clientId. For more information about this please contact us at [email protected].
Full parameter list
VatomIdentitySDK
| Parameter | Description | Default Value |
| --------- | -------------------------------------------------------------------------------------------- | :-----------: |
| clientId | Required. Client ID used to identify your app. | ""
|
| sdkConfig | Optional. SDK Configs | { loginCallbackUri: '/callback', logoutCallbackUri: '/logout-callback', authority: 'https://id.vatom.com', businessId: '' }
|
VatomIdentitySDK Methods
| Name | Description | Response |
| -------------- | --------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------: |
| getAccessToken | Retrieve your access token | {"access_token":"xxx","expires_in":3600,"id_token":"xxx","refresh_token":"xxx","scope":"xxx","token_type":"xxx"}
|
| login | Triggers the login process | |
| logout | Triggers the logout process | |
| onCallbacks | Grants the tokens or remove the tokens. This method should be inside the callbacks components | returns "true" if function was triggered in the callbacks otherwise "false"
|
Example Code using React
import './App.css';
import { useEffect } from 'react';
import { VatomIdentitySDK } from "@vatom/identity-sdk"
function App() {
const clientId = "identity-sdk-test"
const sdkConfig = {}
const identitySdk = new VatomIdentitySDK(clientId, sdkConfig)
const [accessToken, setAccessToken] = useState(identitySdk.getAccessToken())
useEffect(() => {
const triggerCallback = async () => {
// Put this inside your callback components
const res = await identitySdk.onCallbacks()
if (res) {
setAccessToken(identitySdk.getAccessToken())
}
}
triggerCallback()
}, [])
return (
<div className="App">
{!accessToken ? (
<button onClick={identitySdk.login}>Login</button>
) : (
<span>Logged In: </span>
)}
{accessToken && <button onClick={identitySdk.logout}>Logout</button>}
</div>
)
}
export default App;