careful-honey-27437
06/05/2025, 10:40 PMbrief-egg-61061
06/05/2025, 10:40 PMbrief-egg-61061
06/05/2025, 10:41 PMcareful-honey-27437
06/05/2025, 10:43 PMbrief-egg-61061
06/05/2025, 10:43 PMbrief-egg-61061
06/05/2025, 10:43 PMGET /relation-tuples/expand?namespace=<namespace>&object=<object>&relation=<relation>
While the Go SDK documentation references the Expand API, it does not provide a direct code sample for this endpoint. The closest available information is that you would use the Expand API with the object, namespace, and relation you want to inspect, and the response will be a tree of users/roles and their permissions on that object [Expand API Reference](https://www.ory.sh/docs/reference/api#expandPermissions). Summary: - The Expand API is used to list all users/roles and the permits they have on a given object. - No Go SDK code example is provided in the knowledge sources. - You would call the Expand API with the object, namespace, and relation to get the tree of subjects with access. If you need to see the REST API usage or want to see the Go SDK usage for a different API (such as Check or List), please let me know!careful-honey-27437
06/05/2025, 10:46 PMbrief-egg-61061
06/05/2025, 10:46 PMbrief-egg-61061
06/05/2025, 10:46 PMGET /relation-tuples/expand?namespace=<namespace>&object=<object>&relation=<relation>
- Replace <namespace>
, <object>
, and <relation>
with your values. Purpose: This will return a tree of all subjects (users, roles, or subject sets) who have the specified relation (permission) on the object, and why. [Expand API: display who has access to an object](https://www.ory.sh/docs/keto/guides/expand-api-display-who-has-access) --- ## 2. Check API (REST and Go SDK) REST API Request: GET /relation-tuples/check/openapi?namespace=<namespace>&object=<object>&relation=<relation>&subject_id=<subject_id>
- This checks if a specific subject (user or role) has a given permission on an object. Go SDK Example: go check, r, err := ory.PermissionApi.CheckPermission(oryAuthedContext). Namespace(namespace). Object(object). Relation(relation). SubjectId(subjectId). Execute() if err != nil { // handle error } if check.Allowed { fmt.Println(subjectId + " can " + relation + " the " + object) }
This code checks if a subject (e.g., user "Bob") can perform an action (e.g., "view") on an object (e.g., "secret_post") in a namespace (e.g., "Blog") [Go SDK example](https://www.ory.sh/docs/keto/sdk/go). --- ## 3. List API (REST) Purpose: To list all objects a user has access to, or all users who have a specific role or permission, use the List API by querying relationships. REST API Request: GET /relation-tuples?namespace=<namespace>&relation=<relation>&subject_id=<subject_id>
- To list all objects a user has access to, specify the user as subject_id
. - To list all users with a specific role, specify the role as relation
. Example Use Cases: - List all files a user can read. - List all members of a group. For more details and examples, see the [API overview](https://www.ory.sh/docs/keto/concepts/api-overview) and [List API guide](https://www.ory.sh/docs/keto/guides/list-api-display-objects#listing-objects). --- If you need a specific example for any of these APIs, let me know the namespace, object, relation, and subject you want to use!careful-honey-27437
06/06/2025, 5:13 AMbrief-egg-61061
06/06/2025, 5:13 AMbrief-egg-61061
06/06/2025, 5:13 AMAuthorization: Bearer <ORY_API_KEY>
header [Ory API Reference](https://www.ory.sh/docs/reference/api). - For self-hosted Keto, the Expand API does not require authentication by default [Keto REST API Reference](https://www.ory.sh/docs/keto/reference/rest-api). Below is a Go example for Ory Network (with authentication): go package main import ( "fmt" "io/ioutil" "net/http" "os" ) func main() { // Set your Ory Network project URL and API key url := "https://<your-project>.<http://projects.oryapis.com/relation-tuples/expand?namespace=Blog&object=secret_post&relation=view|projects.oryapis.com/relation-tuples/expand?namespace=Blog&object=secret_post&relation=view>" apiKey := os.Getenv("ORY_API_KEY") // Make sure to set this environment variable req, err := http.NewRequest("GET", url, nil) if err != nil { panic(err) } // Add the Authorization header req.Header.Add("Authorization", "Bearer "+apiKey) client := &http.Client{} resp, err := <http://client.Do|client.Do>(req) if err != nil { panic(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { panic(err) } fmt.Println(string(body)) }
Replace <your-project>
with your Ory Network project slug, and ensure the ORY_API_KEY
environment variable is set. - For Ory Network, authentication is required for this endpoint [Ory API Reference](https://www.ory.sh/docs/reference/api). - For self-hosted Keto, authentication is not required for the Expand API [Keto REST API Reference](https://www.ory.sh/docs/keto/reference/rest-api). If you need a self-hosted example (without auth), simply omit the Authorization
header.careful-honey-27437
06/06/2025, 5:21 AMbrief-egg-61061
06/06/2025, 5:21 AMbrief-egg-61061
06/06/2025, 5:22 AMgo package main import ( "fmt" "io/ioutil" "net/http" "os" ) func main() { // Replace with your Ory Network project URL and parameters url := "https://<your-project>.<http://projects.oryapis.com/relation-tuples/expand?namespace=Blog&object=secret_post&relation=view|projects.oryapis.com/relation-tuples/expand?namespace=Blog&object=secret_post&relation=view>" apiKey := os.Getenv("ORY_API_KEY") // Set your API key in the environment req, err := http.NewRequest("GET", url, nil) if err != nil { panic(err) } // Add the Authorization header for Ory Network req.Header.Add("Authorization", "Bearer "+apiKey) req.Header.Add("Accept", "application/json") // Ensure JSON response client := &http.Client{} resp, err := <http://client.Do|client.Do>(req) if err != nil { panic(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { panic(err) } fmt.Println(string(body)) // Prints the JSON response }
- The Accept: application/json
header ensures the response is in JSON format. - The response from the Expand API is a JSON object representing the expanded permission tree [Ory API Reference](https://www.ory.sh/docs/reference/api). If you are using self-hosted Keto, the authentication header is not required for the Expand API [Keto REST API Reference](https://www.ory.sh/docs/keto/reference/rest-api).