Connect Your App
Congratulations! You have succesfully set up an RBAC Policy!
All you have left to do is to follow the instructions on your screen to connect Permit into your application.
Remember that once you connect your app to Permit, you will need to run your application locally
and navigate to localhost:4000
to see the results.
Integrate Permit into your own application
To integrate Permit.io into your own application, you can use the Permit SDK or work with the API directly.
Let's say that you have a web app that uses the Permit SDK to check for permissions. In the app, each user that signs in should have a unique identifier - such as:
- user-id
- Auth0Id
- CognitoId
Your user object probably looks something like the one below (an example from Auth0):
Example user object
{
"user": {
"id": "abc123livrjeoigv",
"tenant": "my-tenant",
"username": "user1",
"password": "xxxxxxx",
"email": "user1@foo.com",
"first_name": "John",
"last_name": "Smith",
"emailVerified": true
}
}
Sync user
This SDK function is used to sync a user's data with the Permit.io PDP upon the users creation.
Once the user has been synced with Permit, you should not use this API call anymore to update the user's Role. Use assignRole
instead.
- .Net
- Python (asyncio)
- Java
- NodeJS
UserKey userObj = new UserKey(user.id, user.first_name, user.last_name, user.email);
permit.Api.SyncUser(userObj);
user = UserInput(user.id, user.first_name, user.last_name, user.email)
permit.write(permit.api.sync_user(user.customId, user.first_name, user.last_name, user.email))
User userObj = new User.Builder(user.id)
.withEmail(user.email)
.withFirstName(user.first_name)
.withLastName(user.last_name)
.build();
user = permit.api.syncUser(userObj);
const userData: IPermitUser = {
key: user.id,
firstName: user.first_name,
lastName: user.last_name,
email: user.email,
roles: [
{
role: "admin",
tenant: board.id,
},
],
};
await permit.write(permit.api.syncUser(userData));
Assign user
To update a user's role after a user has been synced/created, you can use the following function.
- .Net
- Python (asyncio)
- Java
- NodeJS
assignedRole = await permit.Api.AssignRole(user.customId, Role.id, Tenant.externalId);
permit.write(permit.api.assign_role(user.customId, Role.key, Tenant.key))
assignedRole = permit.api.assignRole(user.customId, Role.key, Tenant.externalId);
assignedRole = permit.api.assignRole(user.customId, Role.key, Tenant.key);
List roles
To get the available roles, you can use the following function:
- .Net
- Python (asyncio)
- Java
- NodeJS
Role[] roles = await permit.Api.GetRoles();
To get the available roles, you can use the API.
If you send a request to https://api.permit.io/api/v1/roles
with your webapp bearer token you will get the response:
{
"url": "string",
"data": [
{
"name": "string",
"description": "string",
"attributes": {},
"settings": {},
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"permissions": [],
"isBuiltIn": false
}
]
}
We will update the python command once a new version of this SDK is released.
If you need it for your project, please let us know.
RoleAssignmentList roles = permit.Api.getAssignedRolesInAllTenants();
ISyncedRole[] roles = permit.cache.getRoles();
Manage resources
To sync your resources and actions you can use our Web Application.
Or you can use the SyncResources SDK function.
List tenants
To get the available tenants, you can use the following API Call.