careful-honey-27437
05/02/2025, 6:13 PMbrief-egg-61061
05/02/2025, 6:13 PMbrief-egg-61061
05/02/2025, 6:13 PMbatchCheckPermission
method. While the knowledge sources don't provide a direct example of batch permission checking, I can construct one based on the available information about the API and the single permission check example. Here's an example of how to perform batch permission checks using the Go client: go package main import ( "context" "fmt" "os" ory "<http://github.com/ory/client-go|github.com/ory/client-go>" ) // Use this context to access Ory APIs which require an Ory API Key. var oryAuthedContext = context.WithValue(context.Background(), ory.ContextAccessToken, os.Getenv("ORY_API_KEY")) func main() { // Configure the client configuration := ory.NewConfiguration() configuration.Servers = []ory.ServerConfiguration{ { URL: "<https://your-project-slug.projects.oryapis.com>", // Your Ory Network project URL }, } client := ory.NewAPIClient(configuration) // Create batch check request tuples := []ory.Relationship{ { Namespace: ory.PtrString("Blog"), Object: ory.PtrString("post-1"), Relation: ory.PtrString("view"), SubjectId: ory.PtrString("user-1"), }, { Namespace: ory.PtrString("Blog"), Object: ory.PtrString("post-2"), Relation: ory.PtrString("edit"), SubjectId: ory.PtrString("user-1"), }, { Namespace: ory.PtrString("Blog"), Object: ory.PtrString("post-3"), Relation: ory.PtrString("view"), SubjectId: ory.PtrString("user-2"), }, } body := ory.BatchCheckPermissionBody{ Tuples: tuples, } // Execute batch permission check result, r, err := client.PermissionApi.BatchCheckPermission(oryAuthedContext). BatchCheckPermissionBody(body). Execute() if err != nil { fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) panic("Encountered error: " + err.Error()) } // Process results for i, checkResult := range result.Results { tuple := tuples[i] if checkResult.Allowed { fmt.Printf("%s can %s the %s\n", *tuple.SubjectId, *tuple.Relation, *tuple.Object) } else { fmt.Printf("%s cannot %s the %s\n", *tuple.SubjectId, *tuple.Relation, *tuple.Object) } if checkResult.Error != nil { fmt.Printf("Error checking permission: %s\n", *checkResult.Error) } } }
This example: 1. Sets up the Ory client with your project URL 2. Creates a batch of permission check requests (tuples) 3. Calls the BatchCheckPermission
method 4. Processes the results, which will contain an array of check results in the same order as the input tuples The batch check API is documented in the [Ory API Reference](https://www.ory.sh/docs/reference/api) and returns a 200 status code with results for each permission check in the batch.careful-honey-27437
05/02/2025, 6:54 PMcareful-honey-27437
05/02/2025, 6:54 PMbrief-egg-61061
05/02/2025, 6:54 PMbrief-egg-61061
05/02/2025, 6:54 PMPermissionApi
(singular) rather than PermissionsApi
(plural). Here's the correction for your code: go // Incorrect: // client.PermissionsApi.BatchCheckPermission(...) // Correct: client.PermissionApi.BatchCheckPermission(oryAuthedContext). BatchCheckPermissionBody(body). Execute()
This is confirmed in the documentation examples where the permission-related API is consistently referred to as PermissionApi
(singular form): go check, r, err := ory.PermissionApi.CheckPermission(oryAuthedContext). Namespace(*&namespace). Object(*&object). Relation(*&relation). SubjectId(*&subjectId).Execute()
The [SDK upgrade guide](https://www.ory.sh/docs/guides/upgrade/sdk-v1#permissions--access-control) also shows this naming convention, where permission-related operations are handled by the PermissionApi
module. Make sure you're using the latest version of the Ory client-go SDK, as there have been some changes in the API structure as noted in the upgrade documentation.careful-honey-27437
05/02/2025, 6:55 PMbrief-egg-61061
05/02/2025, 6:55 PMbrief-egg-61061
05/02/2025, 6:55 PMPermissionAPI
(with uppercase "API") rather than PermissionApi
. Here's the corrected code snippet: go // Incorrect: // client.PermissionApi.BatchCheckPermission(...) // Correct: client.PermissionAPI.BatchCheckPermission(oryAuthedContext). BatchCheckPermissionBody(body). Execute()
This appears to be a case sensitivity issue in the Go SDK. While the documentation examples show PermissionApi
with a lowercase "i", the actual implementation in the client uses PermissionAPI
with an uppercase "API". This kind of inconsistency can sometimes occur between documentation and implementation, especially after SDK updates. The [SDK V1 upgrade guide](https://www.ory.sh/docs/guides/upgrade/sdk-v1) mentions significant changes to naming conventions, which might explain this discrepancy. When working with the Go client, follow the case sensitivity that your IDE or compiler suggests, as that reflects the actual implementation in the code.