DotNet Client API
Before going through this guide, make sure you follow the Oso Cloud Quickstart to get your Oso Cloud API Key properly set in your environment.
First, install the OsoCloud
package:
Instantiating an Oso Cloud client
The Oso Cloud client provides an Oso
class
You should instantiate one client and share it across your application. Under the hood, it reuses connections to avoid paying the cost of negotiating a new connection on every request.
Specifying an Oso Fallback host
If you have deployed Oso Fallback nodes to your infrastructure, you may specify the host when instantiating the Oso Cloud client.
Passing application entities into the client
Under the hood, Oso Cloud represents an entity in your application as a combination of a type and an ID, which together uniquely identify the entity.
The DotNet client represents these entities as oso.Value
objects with both Type
and Id
properties.
For example:
You will pass objects like these into nearly every function call you make to the DotNet client.
Centralized Authorization Data API
Oso Cloud clients provide an API to manage authorization data stored directly in Oso Cloud.
Add fact: oso.Tell(name, args)
Adds a fact named name
with the provided arguments. Example:
Add many facts: oso.BulkTell(facts)
For Oso Cloud developer accounts, BulkTell
, BulkDelete
, and Bulk
calls
are limited to 20 facts. If you attempt to send more than 20 facts, the CLI
will return an error.
Adds many facts at once. Example:
Delete fact: oso.Delete(name, args)
Deletes a fact. Does not throw an error if the fact is not found. Example:
Delete many facts: oso.BulkDelete(facts)
Deletes many facts at once. Does not throw an error when some of the facts are not found. Example:
Transactionally delete and add facts: oso.Bulk(delete, tell)
Deletes and adds many facts in one atomic transaction. The deletions are performed before the adds. Does not throw an error when the facts to delete are not found. Example:
List facts: oso.Get(name, args)
For Oso Cloud developer accounts, Get
calls are limited to 1000 results. If
you have more than 1000 facts, the function will return an error.
Lists facts that are stored in Oso Cloud. Can be used to check the existence of a particular fact, or used to fetch all facts that have a particular argument:
Note that null
behaves like a wildcard: passing null, null, anvils
means
"find all facts where anvils
is the third argument, regardless of other
arguments".
Check API
For Oso Cloud developer accounts, the number of context facts per request is limited to 20; and the number of records returned is limited to 1000.
Context facts
Each Check API method has a variant to which you may provide a list of context facts. When Oso Cloud performs a check, it will consider these context facts in addition to any other facts you've previously added. Context facts are only used in the API call in which they're provided-- they do not persist across requests. Learn more about context facts.
Check a permission: oso.Authorize(actor, action, resource)
Determines whether or not an action is allowed, based on a combination of authorization data and policy logic. Example:
You may provide a slice of context facts. Example:
Check authorized resources: oso.AuthorizeResources(actor, action, resources)
Returns a subset of resources
on which an actor can perform a particular action.
Ordering and duplicates, if any exist, are preserved.
For Oso Cloud developer accounts, the number of input resources is limited to 1000.
Example:
You may provide a slice of context facts. Example:
List authorized resources: osoClient.List(actor, action, resourceType)
Fetches a list of resource IDs on which an actor can perform a particular action. Example:
List authorized actions: oso.Actions(actor, resource)
Fetches a list of actions which an actor can perform on a particular resource. Example:
Query for anything: oso.Query(rule)
Query Oso Cloud for any predicate and any combination of concrete and wildcard arguments.
Unlike oso.Get
, which only lists facts you've added, you can use oso.Query
to list derived
information about any rule in your policy.
Example:
Note that null
behaves like a wildcard. Passing "allow", null, null, anvils
means "find anyone who can do anything to anvils
". null
also
behaves like a wildcard in return values from oso.Query
. Additionally, if
you want to query over all instances of a particular type, pass an oso.Value
with a Type
but no Id
. For example, "allow", bob, "read", oso.Value("Repository", null)
will query for all the objects of type
"Repository"
that bob
can read
.
Learn more about how to query Oso Cloud.
List, Actions, and Query can also take Context Facts.
Distributed Check API
The distributed check API lets you perform authorization using data that's distributed across Oso Cloud and your own database.
After creating your local authorization configuration, provide the path to the YAML file that specifies how to resolve facts in your database.
For more information, see Local Authorization.
List authorized resources with distributed data: oso.ListLocal(actor, action, resource_type, column)
Fetches a filter that can be applied to a database query to return just the resources on which an actor can perform an action. Example:
Check a permission with distributed data: oso.AuthorizeLocal(actor, action, resource)
Fetches a query that can be run against your database to determine whether an actor can perform an action on a resource. Example:
List authorized actions with distributed data: oso.ActionsLocal(actor, resource)
Fetches a query that can be run against your database to fetch the actions an actor can perform on a resource.
Policy API
Update the active policy: oso.Policy(policy)
Updates the policy in Oso Cloud. The string passed into this method should be written in Polar. Example:
This command will run any tests defined in your policy. If one or more of these tests fail, your policy will not be updated.
Get policy metadata: oso.get_policy_metadata()
Returns metadata about the currently active policy. Example:
See the Policy Metadata guide for more information on use cases.
Talk to an Oso Engineer
If you'd like to learn more about using Oso Cloud in your app or have any questions about this guide, schedule a 1x1 with an Oso engineer. We're happy to help.