cURL
curl --request POST \
--url https://api.osohq.com/api/list_query \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"query": {
"actor_type": "<string>",
"actor_id": "<string>",
"action": "<string>",
"resource_type": "<string>",
"page_size": 10000,
"context_facts": [],
"page_token": null
},
"column": "<string>",
"data_bindings": "<string>"
}
'from oso_cloud import Oso, Value
import os
from sqlalchemy import select, text
from oso_cloud import Oso, Value
oso = Oso(api_key=os.environ.get('OSO_CLOUD_API_KEY', None))
# Generate SQL condition for authorized resources
alice = Value("User", "alice")
sql_condition = oso.list_local(alice, "read", "Issue", "id")
# Use with SQLAlchemy
authorized_issues = session.scalars(
select(Issues).filter(text(sql_condition))
).all()
print(f"Found {len(authorized_issues)} authorized issues")import { Oso } from 'oso-cloud';
const apiKey = process.env.OSO_CLOUD_API_KEY;
const oso = new Oso("https://cloud.osohq.com", apiKey);
// Generate SQL condition for authorized resources
const alice = { type: "User", id: "alice" };
const sqlCondition = await oso.listLocal(alice, "read", "Issue", "id");
// Use with database query (example with Kysely)
const authorized_issues = await db
.selectFrom("issues")
.where(sql.raw<boolean>(sqlCondition))
.selectAll()
.execute();
console.log("Authorized issues:", authorized_issues.length);package main
import (
"log"
"os"
oso "github.com/osohq/go-oso-cloud/v2"
)
func main() {
apiKey := os.Getenv("OSO_CLOUD_API_KEY")
osoClient := oso.NewClient("https://cloud.osohq.com", apiKey)
// Generate SQL condition for authorized resources
user := oso.NewValue("User", "alice")
sqlCondition, err := osoClient.ListLocal(user, "read", "Issue", "id")
if err != nil {
log.Fatal(err)
}
// Use with GORM
var issues []Issue
db.Find(&issues, sqlCondition)
fmt.Printf("Found %d authorized issues\n", len(issues))
}package com.mycompany;
import java.io.IOException;
import java.util.List;
import com.osohq.oso_cloud.Oso;
import com.osohq.oso_cloud.api.ApiException;
import com.osohq.oso_cloud.api.Value;
public class App {
public static void main(String[] args) {
String apiKey = System.getenv("OSO_CLOUD_API_KEY");
Oso oso = new Oso(apiKey);
try {
// Generate SQL condition for authorized resources
Value alice = new Value("User", "alice");
String sqlCondition = oso.listLocal(alice, "read", "Issue", "id");
// Use with JPA/Hibernate
List<Issue> authorizedIssues = entityManager.createQuery(
"SELECT i FROM Issue i WHERE " + sqlCondition, Issue.class)
.getResultList();
System.out.println("Found " + authorizedIssues.size() + " authorized issues");
} catch (IOException | ApiException e) {
System.err.println("Error: " + e.getMessage());
}
}
}require 'oso-cloud'
api_key = ENV.fetch('OSO_CLOUD_API_KEY', nil)
oso = OsoCloud::Oso.new(url: "https://cloud.osohq.com", api_key: api_key)
# Generate SQL condition for authorized resources
alice = OsoCloud::Value.new(type: "User", id: "alice")
sql_condition = oso.list_local(alice, "read", "Issue", "id")
# Use with ActiveRecord
authorized_issues = Issue.where(sql_condition)
puts "Found #{authorized_issues.count} authorized issues"using OsoCloud;
using Microsoft.EntityFrameworkCore;
string? apiKey = Environment.GetEnvironmentVariable("OSO_CLOUD_API_KEY");
var oso = new Oso("https://api.osohq.com", apiKey);
// Generate SQL condition for authorized resources
var alice = new Value("User", "alice");
string sqlCondition = await oso.ListLocal(alice, "read", "Issue", "id");
// Use with Entity Framework
var authorizedIssues = await context.Issues
.FromSqlRaw($"SELECT * FROM Issues WHERE {sqlCondition}")
.ToListAsync();
Console.WriteLine($"Found {authorizedIssues.Count} authorized issues");{
"sql": "<string>"
}{
"message": "<string>"
}Local Check API
Post list query
Fetches a filter that can be applied to a database query to return just the resources on which an actor can perform an action.
POST
/
list_query
cURL
curl --request POST \
--url https://api.osohq.com/api/list_query \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"query": {
"actor_type": "<string>",
"actor_id": "<string>",
"action": "<string>",
"resource_type": "<string>",
"page_size": 10000,
"context_facts": [],
"page_token": null
},
"column": "<string>",
"data_bindings": "<string>"
}
'from oso_cloud import Oso, Value
import os
from sqlalchemy import select, text
from oso_cloud import Oso, Value
oso = Oso(api_key=os.environ.get('OSO_CLOUD_API_KEY', None))
# Generate SQL condition for authorized resources
alice = Value("User", "alice")
sql_condition = oso.list_local(alice, "read", "Issue", "id")
# Use with SQLAlchemy
authorized_issues = session.scalars(
select(Issues).filter(text(sql_condition))
).all()
print(f"Found {len(authorized_issues)} authorized issues")import { Oso } from 'oso-cloud';
const apiKey = process.env.OSO_CLOUD_API_KEY;
const oso = new Oso("https://cloud.osohq.com", apiKey);
// Generate SQL condition for authorized resources
const alice = { type: "User", id: "alice" };
const sqlCondition = await oso.listLocal(alice, "read", "Issue", "id");
// Use with database query (example with Kysely)
const authorized_issues = await db
.selectFrom("issues")
.where(sql.raw<boolean>(sqlCondition))
.selectAll()
.execute();
console.log("Authorized issues:", authorized_issues.length);package main
import (
"log"
"os"
oso "github.com/osohq/go-oso-cloud/v2"
)
func main() {
apiKey := os.Getenv("OSO_CLOUD_API_KEY")
osoClient := oso.NewClient("https://cloud.osohq.com", apiKey)
// Generate SQL condition for authorized resources
user := oso.NewValue("User", "alice")
sqlCondition, err := osoClient.ListLocal(user, "read", "Issue", "id")
if err != nil {
log.Fatal(err)
}
// Use with GORM
var issues []Issue
db.Find(&issues, sqlCondition)
fmt.Printf("Found %d authorized issues\n", len(issues))
}package com.mycompany;
import java.io.IOException;
import java.util.List;
import com.osohq.oso_cloud.Oso;
import com.osohq.oso_cloud.api.ApiException;
import com.osohq.oso_cloud.api.Value;
public class App {
public static void main(String[] args) {
String apiKey = System.getenv("OSO_CLOUD_API_KEY");
Oso oso = new Oso(apiKey);
try {
// Generate SQL condition for authorized resources
Value alice = new Value("User", "alice");
String sqlCondition = oso.listLocal(alice, "read", "Issue", "id");
// Use with JPA/Hibernate
List<Issue> authorizedIssues = entityManager.createQuery(
"SELECT i FROM Issue i WHERE " + sqlCondition, Issue.class)
.getResultList();
System.out.println("Found " + authorizedIssues.size() + " authorized issues");
} catch (IOException | ApiException e) {
System.err.println("Error: " + e.getMessage());
}
}
}require 'oso-cloud'
api_key = ENV.fetch('OSO_CLOUD_API_KEY', nil)
oso = OsoCloud::Oso.new(url: "https://cloud.osohq.com", api_key: api_key)
# Generate SQL condition for authorized resources
alice = OsoCloud::Value.new(type: "User", id: "alice")
sql_condition = oso.list_local(alice, "read", "Issue", "id")
# Use with ActiveRecord
authorized_issues = Issue.where(sql_condition)
puts "Found #{authorized_issues.count} authorized issues"using OsoCloud;
using Microsoft.EntityFrameworkCore;
string? apiKey = Environment.GetEnvironmentVariable("OSO_CLOUD_API_KEY");
var oso = new Oso("https://api.osohq.com", apiKey);
// Generate SQL condition for authorized resources
var alice = new Value("User", "alice");
string sqlCondition = await oso.ListLocal(alice, "read", "Issue", "id");
// Use with Entity Framework
var authorizedIssues = await context.Issues
.FromSqlRaw($"SELECT * FROM Issues WHERE {sqlCondition}")
.ToListAsync();
Console.WriteLine($"Found {authorizedIssues.Count} authorized issues");{
"sql": "<string>"
}{
"message": "<string>"
}Was this page helpful?
⌘I