https://github.com/singhhp1069/authonomy-sdk-js
Authonomy javascript sdk for the demo.
https://github.com/singhhp1069/authonomy-sdk-js
Last synced: about 1 year ago
JSON representation
Authonomy javascript sdk for the demo.
- Host: GitHub
- URL: https://github.com/singhhp1069/authonomy-sdk-js
- Owner: singhhp1069
- License: other
- Created: 2024-01-07T10:37:01.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-01-07T14:34:43.000Z (over 2 years ago)
- Last Synced: 2025-03-11T16:46:12.320Z (over 1 year ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AuthonomySDK
[](https://badge.fury.io/js/authonomysdk)
AuthonomySDK is a JavaScript library providing easy integration with the Authonomy service for web applications. It simplifies user authentication and authorization processes, leveraging Authonomy's secure backend.
## Features
- User Sign-up and Authentication
- Access Token Generation
- Access List Retrieval
- Access Verification
## Installation
To install AuthonomySDK, use npm:
```bash
npm install authonomysdk
```
## Usage
Here's a quick example to get you started:
```js
import { AuthonomySDK } from 'authonomysdk';
const sdk = new AuthonomySDK({
appDid: "your_app_did",
appSecret: "your_app_secret",
serviceUrl: "http://localhost:8081"
});
// Sign up or authenticate a user
sdk.signUp((data) => {
console.log("User data:", data);
});
// Fetch access token
sdk.getAccessToken("your_oauth_credential", "your_policy_credential", (error, data) => {
if (error) {
console.error("Error:", error);
} else {
console.log("Access token:", data.access_token);
}
});
// Verify access
// Developer can use it as a middleware too
// response: "true" / "false"
sdk.verifyAccess(accessToken, attribute, (error, data) => {
if (error) {
console.error('Failed to verify access:', error);
return;
}
console.log('Access verification:', data);
});
// Get access list
// example response:
// {
// "application_policy": {
// "id": "did:key:z6MkmrniEq3Cg7bv21BVbX8qkgJUPsAT6yPcBXoMKBvYtMAu",
// "roles": [
// {
// "permissions": [
// "create_user",
// "delete_user",
// "edit_settings"
// ],
// "roleName": "admin"
// },
// {
// "permissions": [
// "view_content",
// "comment"
// ],
// "roleName": "user"
// }
// ]
// },
// "user_access_list": {
// "id": "did:key:z6Mkqw8Lz1UVwx9U12CUJ9gQdo7Xsuf75YeM9Zkc52hSw2Xn",
// "roles": [
// {
// "permissions": [
// "view_content",
// "comment"
// ],
// "roleName": "user"
// }
// ]
// }
// }
sdk.getAccessList(accessToken, (error, data) => {
if (error) {
console.error('Failed to get access list:', error);
return;
}
console.log('Access list:', data);
});
```
### important: this is a proof-of-concept for demo purpose only not for production