Skip to main content
Rather than converting your authorization data to facts and sending it to Oso with every authorization request, you can use Local Authorization. This will instruct Oso to construct a query to fetch that data directly from your database. Setup with two requirements:
  1. A configuration file that maps your facts to SQL queries
  2. Use the Local Authorization API in your application code

Write the configuration file

You configure Local Authorization with a yaml file passed to the Oso Cloud client on instantiation. This configuration file lists the fact signatures used for your authorization queries. It also associates them with the SQL that generates the facts from your application data. Recall that you send up to three context facts to Oso for any “read repository” authorization request:
These are the fact signatures that to include in the config file.
local_authorization_config.yaml
Note the following:
  • Any value returned by the query is represented in the fact signature by using the wildcard character (_).
  • Any value not returned from a query must be explicitly specified in the fact signature by its type and value (e.g. String:parent).
  • The sql_types: section is optional, but strongly recommended.

Use the Local Authorization API

You provide this configuration file to the Oso Cloud client when you instantiate it. Then you use the Local Authorization API to make authorization decisions without passing data to Oso Cloud. In the Typescript SDK, you use authorizeLocal in place of authorize.
backend/src/authz.ts
Major changes are highlighted:
  • The osoClient instantiation is modified to include the local_authorization_config.yaml file.
  • The call to authorize() is replaced with a call to authorizeLocal()
  • The query returned from authorizeLocal() is executed against the database to resolve the authorization request
Notice that the canReadRepo() function is smaller. This is because we do not need code in that function to get role data and convert it to facts. It is handled by the query returned from authorizeLocal() now.
You can write the query that authorizeLocal() returns to a log if you’d like to inspect it.
Confirm that the results from Oso Cloud are still correct.
The results are identical to our previous authorization code. All that remains is to replace the original authorization logic with the Oso Cloud version.