wide-machine-60917
04/27/2023, 4:13 PMhigh-optician-2097
high-optician-2097
wide-machine-60917
04/28/2023, 7:19 AMsteep-lamp-91158
const metaCallback: CallMetadataGenerator = (_, callback) => {
const meta = new grpc.Metadata()
if (token) {
meta.add("authorization", "Bearer " + token)
}
callback(null, meta)
}
const callCreds = grpc.credentials.createFromMetadataGenerator(metaCallback)
so you basically just want to set the authorization header to Bearer your_api_keysteep-lamp-91158
wide-machine-60917
04/28/2023, 8:31 AMsteep-lamp-91158
steep-lamp-91158
Access & APIswide-machine-60917
04/28/2023, 11:27 AMfunc testGRPC() {
conn, err := grpc.Dial("MY_ORY_ADDRESS:4467", grpc.WithInsecure(), grpc.WithUnaryInterceptor(authInterceptor("MY_ORY_TOKEN")))
if err != nil {
panic("Encountered error: " + err.Error())
}
fmt.Println("State: ", conn.GetState())
client := acl.NewWriteServiceClient(conn)
_, err = client.TransactRelationTuples(context.Background(), &acl.TransactRelationTuplesRequest{
RelationTupleDeltas: []*acl.RelationTupleDelta{
{
Action: acl.RelationTupleDelta_INSERT,
RelationTuple: &acl.RelationTuple{
Namespace: "messages",
Object: "02y_15_4w350m3",
Relation: "decypher",
Subject: &acl.Subject{},
},
},
},
})
if err != nil {
panic("Encountered error: " + err.Error())
}
fmt.Println("Successfully created tuple")
}
func authInterceptor(accessToken string) grpc.UnaryClientInterceptor {
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
newCtx := metadata.AppendToOutgoingContext(ctx, "authorization", "Bearer "+accessToken)
return invoker(newCtx, method, req, reply, cc, opts...)
}
}wide-machine-60917
04/28/2023, 11:29 AMError while dialing: dial tcp _IP_ADDRESS_:4467steep-lamp-91158
steep-lamp-91158
steep-lamp-91158
wide-machine-60917
04/28/2023, 11:32 AMsteep-lamp-91158
<http://elegant-nobel-fhv4ruffh9.projects.oryapis.com|elegant-nobel-fhv4ruffh9.projects.oryapis.com>steep-lamp-91158
grpc.WithInsecure?wide-machine-60917
04/28/2023, 11:35 AMwide-machine-60917
04/28/2023, 11:36 AMsteep-lamp-91158
package main
import (
"context"
"fmt"
"<http://google.golang.org/grpc/credentials|google.golang.org/grpc/credentials>"
"os"
rts "<http://github.com/ory/keto/proto/ory/keto/relation_tuples/v1alpha2|github.com/ory/keto/proto/ory/keto/relation_tuples/v1alpha2>"
"<http://google.golang.org/grpc|google.golang.org/grpc>"
"<http://google.golang.org/grpc/metadata|google.golang.org/grpc/metadata>"
)
func main() {
conn, err := grpc.Dial("<http://elegant-nobel-fhv4ruffh9.projects.oryapis.com:443|elegant-nobel-fhv4ruffh9.projects.oryapis.com:443>", grpc.WithTransportCredentials(credentials.NewTLS(nil)), grpc.WithAuthority("<http://elegant-nobel-fhv4ruffh9.projects.oryapis.com|elegant-nobel-fhv4ruffh9.projects.oryapis.com>"), grpc.WithUnaryInterceptor(authInterceptor(os.Getenv("ORY_API_KEY"))))
if err != nil {
panic("Encountered error: " + err.Error())
}
fmt.Println("State: ", conn.GetState())
client := rts.NewWriteServiceClient(conn)
_, err = client.TransactRelationTuples(context.Background(), &rts.TransactRelationTuplesRequest{
RelationTupleDeltas: []*rts.RelationTupleDelta{
{
Action: rts.RelationTupleDelta_ACTION_INSERT,
RelationTuple: &rts.RelationTuple{
Namespace: "File",
Object: "foo",
Relation: "owner",
Subject: rts.NewSubjectSet("User", "john", ""),
},
},
},
})
if err != nil {
panic("Encountered error: " + err.Error())
}
fmt.Println("Successfully created tuple")
}
func authInterceptor(accessToken string) grpc.UnaryClientInterceptor {
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
newCtx := metadata.AppendToOutgoingContext(ctx, "authorization", "Bearer "+accessToken)
return invoker(newCtx, method, req, reply, cc, opts...)
}
}
This worked for me, maybe you used an old version of the grpc client?steep-lamp-91158
steep-lamp-91158
grpc.WithAuthority is not neededwide-machine-60917
04/28/2023, 11:49 AMwide-machine-60917
04/28/2023, 11:54 AMgrpc.WithTransportCredentials(credentials.NewTLS(nil)) Thanks.
Probably it's good to add somewhere in the documentation, or i'll make PR later to Ory Doc.
Thanks!steep-lamp-91158
wide-machine-60917
04/28/2023, 2:51 PMsnaptoken:"not yet implemented"
with this code below, what might be wrong?
res, err := check.Check(ctx, &rts.CheckRequest{
Namespace: "LegalEntity",
Object: "entity1",
Relation: "readers",
Tuple: &rts.RelationTuple{
Namespace: "User",
Subject: &rts.Subject{
Ref: &rts.Subject_Id{
Id: "<mailto:[email protected]|[email protected]>",
},
},
},
})steep-lamp-91158
steep-lamp-91158
wide-machine-60917
04/28/2023, 2:56 PMsteep-lamp-91158
steep-lamp-91158
wide-machine-60917
04/28/2023, 3:02 PMTuple: &rts.RelationTuple{
Namespace: "LegalEntity",
Object: "entity1",
Relation: "readers",
Subject: &rts.Subject{
Ref: &rts.Subject_Set{
Set: &rts.SubjectSet{
Namespace: "User",
Object: "<mailto:[email protected]|[email protected]>",
},
},
},
},wide-machine-60917
04/28/2023, 3:02 PMsteep-lamp-91158
wide-machine-60917
04/28/2023, 3:03 PMsteep-lamp-91158
steep-lamp-91158
wide-machine-60917
04/28/2023, 3:03 PMwide-machine-60917
04/28/2023, 3:04 PMsteep-lamp-91158