Query (roles_pbac) Endpoint
Used to make requests to the control API that controls your tenant's roles, classes, and policy (among other things). Standard GraphQL endpoint that take the usual fields "query", "variables", and "operationName".
For all requests send to the endpoints in "routes", set an HTTP "Authorization" header to the text "Bearer " and then the contents of the "access_token" field. This token will be checked by the Devii server, and its cryptographic signature means it can't be changed without being invalidated, and can't be faked. It will positively identfiy the logged in role as being authorized.
The access token is not permanent: it has a default expiration time of 1 day (86400 seconds).
The refresh token can be used to request a new access token, by sending a GET request to the /auth endpoint with the Authorization header set to "Bearer [refresh_token]". This will issue a new access token and resend the other data. The refresh token has a default expiration time of 7 days (604800 seconds).
{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzUxMiJ9...",
"message": "Logged in as demo_user.",
"refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzUxMiJ9...",
"roleid": 1611,
"routes": {
"base": "https://api.devii.io/",
"query": "https://api.devii.io/query",
"roles_pbac": "https://api.devii.io/roles_pbac"
},
{Truncated Schema...}
}
Example
{
role {
roleid
name
}
}
Show Code
const ROLES_PBAC = "https://api.devii.io/roles_pbac";
- JS Fetch
- Apollo Client
- Axios
const ACCESS_TOKEN = auth_response.access_token;
const ROLES_PBAC = auth_response.routes.roles_pbac;
const query = "{\r\n role {\r\n roleid\r\n name\r\n }\r\n}";
var myHeaders = new Headers();
myHeaders.append("Authorization", `Bearer ${ACCESS_TOKEN}`);
myHeaders.append("Content-Type", "application/json");
var graphql = JSON.stringify({
query: query,
variables: {},
});
var requestOptions = {
method: "POST",
headers: myHeaders,
body: graphql,
redirect: "follow",
};
fetch(ROLES_PBAC, requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));
import { ApolloClient, InMemoryCache, gql } from "@apollo/client";
const ACCESS_TOKEN = auth_response.access_token;
const ROLES_PBAC = auth_response.routes.roles_pbac;
const query = "{\r\n role {\r\n roleid\r\n name\r\n }\r\n}";
const client = new ApolloClient({
uri: ROLES_PBAC,
headers: {
Authorization: `Bearer ${ACCESS_TOKEN}`,
},
cache: new InMemoryCache(),
});
client
.query({
query: gql`
query {
${query}
}
`,
variables: {},
})
.then((result) => {
return {
data: result.data[reducedResource],
};
})
.catch((error) => {
throw new Error(error);
});
import axios from "axios";
const ACCESS_TOKEN = auth_response.access_token;
const ROLES_PBAC = auth_response.routes.roles_pbac;
const query = "{\r\n role {\r\n roleid\r\n name\r\n }\r\n}";
const queryConfig = {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${ACCESS_TOKEN}`,
},
};
const data = new FormData();
data.append("query", query);
data.append("variables", `{}`);
const result = await axios.post(ROLES_PBAC, data, queryConfig);
Password Strength and Token Expiration
The tenant_auth_policy table is used for password validation, and for setting the expiration times of JWT authentication tokens.
mutation ($tenant_auth_policyInput: tenant_auth_policyInput) {
update_tenant_auth_policy(input: $tenant_auth_policyInput) {
length
uppercase
numbers
special
nonletters
strength
access_expiration
refresh_expiration
}
}
{
"tenant_auth_policyInput": {
"length": 8,
"uppercase": 1,
"numbers": 1,
"special": 1,
"nonletters": 1,
"strength": 0.5,
"access_expiration": 86400,
"refresh_expiration": 604800
}
}
Utility functions
These functions are designed to perform miscellaneous operations that are not easily represented by simple object queries and mutations, providing introspection and role control as well as statistical and schema insights into your tenant.
introspect
GenericScalar
Reintrospect and reload the database schema. Returns the new schema JSON.
Show Example Query
{
Utility {
introspect
}
}