Skip to main content
POST
/
authorize_query
cURL
curl --request POST \
  --url https://api.osohq.com/api/authorize_query \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "query": {
    "actor_type": "<string>",
    "actor_id": "<string>",
    "action": "<string>",
    "resource_type": "<string>",
    "resource_id": "<string>",
    "context_facts": []
  },
  "data_bindings": "<string>"
}
'
from oso_cloud import Oso, Value
import os
from sqlalchemy import text
from oso_cloud import Oso, Value

oso = Oso(api_key=os.environ.get('OSO_CLOUD_API_KEY', None))

# Generate authorization check SQL
alice = Value("User", "alice")
issue = Value("Issue", "123")
query = oso.authorize_local(alice, "read", issue)

# Execute with SQLAlchemy
authorized = session.execute(text(query)).scalar()

if not authorized:
raise Exception("Access denied")
import { Oso } from 'oso-cloud';

const apiKey = process.env.OSO_CLOUD_API_KEY;
const oso = new Oso("https://cloud.osohq.com", apiKey);

// Generate authorization check SQL
const alice = { type: "User", id: "alice" };
const issue = { type: "Issue", id: "123" };
const query = await oso.authorizeLocal(alice, "read", issue);

// Execute with database (example with raw SQL)
const result = await sql.raw(query).execute(db);
const { allowed } = result.rows[0];

if (!allowed) {
throw new Error("Access denied");
}
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 authorization check SQL
alice := oso.NewValue("User", "alice")
issue := oso.NewValue("Issue", "123")
query, err := osoClient.AuthorizeLocal(alice, "read", issue)
if err != nil {
log.Fatal(err)
}

// Execute with GORM
var authorizeResult AuthorizeResult
db.Raw(query).Scan(&authorizeResult)

if !authorizeResult.Allowed {
return fmt.Errorf("access denied")
}
}
package com.mycompany;

import java.io.IOException;
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 authorization check SQL
Value alice = new Value("User", "alice");
Value issue = new Value("Issue", "123");
String query = oso.authorizeLocal(alice, "read", issue);

// Execute with database (example with JPA/Hibernate)
Boolean authorized = (Boolean) entityManager.createNativeQuery(query)
.getSingleResult();

if (!authorized) {
throw new SecurityException("Access denied");
}
} 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 authorization check SQL
alice = OsoCloud::Value.new(type: "User", id: "alice")
issue = OsoCloud::Value.new(type: "Issue", id: "123")
query = oso.authorize_local(alice, "read", issue)

# Execute with ActiveRecord
authorized = ActiveRecord::Base.connection.execute(query).values.first.first

raise "Access denied" unless authorized
using OsoCloud;

string? apiKey = Environment.GetEnvironmentVariable("OSO_CLOUD_API_KEY");
var oso = new Oso("https://api.osohq.com", apiKey);

// Generate authorization check SQL
var alice = new Value("User", "alice");
var issue = new Value("Issue", "123");
string query = await oso.AuthorizeLocal(alice, "read", issue);

// Execute with Entity Framework
bool authorized = await context.Database.SqlQueryRaw<bool>(query).FirstAsync();

if (!authorized) {
throw new UnauthorizedAccessException("Access denied");
}
{
  "sql": "<string>"
}
{
"message": "<string>"
}

Authorizations

Authorization
string
header
required

Requires an API key to access.

Body

application/json
query
object
required
data_bindings
string
required

Response

sql
string
required