cURL
curl --request POST \
--url https://api.osohq.com/api/authorize \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"actor_type": "<string>",
"actor_id": "<string>",
"action": "<string>",
"resource_type": "<string>",
"resource_id": "<string>"
}
'import os
from oso_cloud import Oso, Value
oso = Oso(api_key=os.environ.get('OSO_CLOUD_API_KEY', None))
# Basic authorization check
alice = Value("User", "alice")
repository = Value("Repository", "anvils")
if not oso.authorize(alice, "read", repository):
raise Exception("Action is not allowed")
# With context facts
issue = Value("Issue", "123")
authorized = oso.authorize(
alice,
"read",
issue,
context_facts=[("has_relation", issue, "parent", repository)]
)import { Oso } from 'oso-cloud';
const apiKey = process.env.OSO_CLOUD_API_KEY;
const oso = new Oso("https://cloud.osohq.com", apiKey);
// Basic authorization check
const alice = { type: "User", id: "alice" };
const repository = { type: "Repository", id: "anvils" };
const authorized = await oso.authorize(alice, "read", repository);
if (!authorized) {
throw new Error("Access denied");
}
// With context facts for additional information
const issue = { type: "Issue", id: "123" };
const contextAuthorized = await oso.authorize(
alice,
"read",
issue,
[["has_relation", issue, "parent", repository]] // Context facts
);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)
// Basic authorization check
user := oso.NewValue("User", "alice")
repository := oso.NewValue("Repository", "anvils")
allowed, err := osoClient.Authorize(user, "read", repository)
if err != nil {
log.Fatal(err)
}
if !allowed {
return fmt.Errorf("access denied")
}
// With context facts
issue := oso.NewValue("Issue", "123")
contextFacts := []oso.Fact{
oso.NewFact("has_relation", issue, oso.String("parent"), repository),
}
allowed, err = osoClient.AuthorizeWithContext(user, "read", issue, contextFacts)
}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 {
// Basic authorization check
Value alice = new Value("User", "alice");
Value repository = new Value("Repository", "anvils");
boolean authorized = oso.authorize(alice, "read", repository);
if (!authorized) {
throw new RuntimeException("Access denied");
}
// With context facts for additional information
Value issue = new Value("Issue", "123");
boolean contextAuthorized = oso.authorize(alice, "read", issue,
Arrays.asList(Arrays.asList("has_relation", issue, "parent", repository)));
} 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)
# Basic authorization check
alice = OsoCloud::Value.new(type: "User", id: "alice")
repository = OsoCloud::Value.new(type: "Repository", id: "anvils")
authorized = oso.authorize(alice, "read", repository)
raise "Access denied" unless authorized
# With context facts
issue = OsoCloud::Value.new(type: "Issue", id: "123")
context_authorized = oso.authorize(alice, "read", issue,
context_facts: [["has_relation", issue, "parent", repository]])using OsoCloud;
string? apiKey = Environment.GetEnvironmentVariable("OSO_CLOUD_API_KEY");
var oso = new Oso("https://api.osohq.com", apiKey);
// Basic authorization check
var alice = new Value("User", "alice");
var repository = new Value("Repository", "anvils");
bool authorized = await oso.Authorize(alice, "read", repository);
if (!authorized) {
throw new UnauthorizedAccessException("Access denied");
}
// With context facts for additional information
var issue = new Value("Issue", "123");
bool contextAuthorized = await oso.Authorize(alice, "read", issue,
contextFacts: new[] { new[] { "has_relation", issue, "parent", repository } });{
"allowed": true
}{
"message": "<string>"
}Check API
Post authorize
Determines whether or not an actor can take an action on a resource, based on a combination of authorization data and policy logic.
POST
/
authorize
cURL
curl --request POST \
--url https://api.osohq.com/api/authorize \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"actor_type": "<string>",
"actor_id": "<string>",
"action": "<string>",
"resource_type": "<string>",
"resource_id": "<string>"
}
'import os
from oso_cloud import Oso, Value
oso = Oso(api_key=os.environ.get('OSO_CLOUD_API_KEY', None))
# Basic authorization check
alice = Value("User", "alice")
repository = Value("Repository", "anvils")
if not oso.authorize(alice, "read", repository):
raise Exception("Action is not allowed")
# With context facts
issue = Value("Issue", "123")
authorized = oso.authorize(
alice,
"read",
issue,
context_facts=[("has_relation", issue, "parent", repository)]
)import { Oso } from 'oso-cloud';
const apiKey = process.env.OSO_CLOUD_API_KEY;
const oso = new Oso("https://cloud.osohq.com", apiKey);
// Basic authorization check
const alice = { type: "User", id: "alice" };
const repository = { type: "Repository", id: "anvils" };
const authorized = await oso.authorize(alice, "read", repository);
if (!authorized) {
throw new Error("Access denied");
}
// With context facts for additional information
const issue = { type: "Issue", id: "123" };
const contextAuthorized = await oso.authorize(
alice,
"read",
issue,
[["has_relation", issue, "parent", repository]] // Context facts
);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)
// Basic authorization check
user := oso.NewValue("User", "alice")
repository := oso.NewValue("Repository", "anvils")
allowed, err := osoClient.Authorize(user, "read", repository)
if err != nil {
log.Fatal(err)
}
if !allowed {
return fmt.Errorf("access denied")
}
// With context facts
issue := oso.NewValue("Issue", "123")
contextFacts := []oso.Fact{
oso.NewFact("has_relation", issue, oso.String("parent"), repository),
}
allowed, err = osoClient.AuthorizeWithContext(user, "read", issue, contextFacts)
}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 {
// Basic authorization check
Value alice = new Value("User", "alice");
Value repository = new Value("Repository", "anvils");
boolean authorized = oso.authorize(alice, "read", repository);
if (!authorized) {
throw new RuntimeException("Access denied");
}
// With context facts for additional information
Value issue = new Value("Issue", "123");
boolean contextAuthorized = oso.authorize(alice, "read", issue,
Arrays.asList(Arrays.asList("has_relation", issue, "parent", repository)));
} 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)
# Basic authorization check
alice = OsoCloud::Value.new(type: "User", id: "alice")
repository = OsoCloud::Value.new(type: "Repository", id: "anvils")
authorized = oso.authorize(alice, "read", repository)
raise "Access denied" unless authorized
# With context facts
issue = OsoCloud::Value.new(type: "Issue", id: "123")
context_authorized = oso.authorize(alice, "read", issue,
context_facts: [["has_relation", issue, "parent", repository]])using OsoCloud;
string? apiKey = Environment.GetEnvironmentVariable("OSO_CLOUD_API_KEY");
var oso = new Oso("https://api.osohq.com", apiKey);
// Basic authorization check
var alice = new Value("User", "alice");
var repository = new Value("Repository", "anvils");
bool authorized = await oso.Authorize(alice, "read", repository);
if (!authorized) {
throw new UnauthorizedAccessException("Access denied");
}
// With context facts for additional information
var issue = new Value("Issue", "123");
bool contextAuthorized = await oso.Authorize(alice, "read", issue,
contextFacts: new[] { new[] { "has_relation", issue, "parent", repository } });{
"allowed": true
}{
"message": "<string>"
}Was this page helpful?
⌘I