Hi, how to generate token with an
# spicedb
z
Hi, how to generate token with an instance?
v
what instance are you talking to? your own spicedb? authzed serverless? authzed dedicated?
z
My own spicedb created by docker
I generated token by this way:
Copy code
docker run --name spicedb -p 50051:50051 quay.io/authzed/spicedb serve --grpc-preshared-key "somerandomkeyhere"

printf "sdbst_h256_%s\n" $(echo -n somerandomkeyhere | sha256sum | cut -d' ' -f1)
v
well your preshared-key is somerandomkeyhere, so that's what you have to pass via the gRPC API
Wait, what you mean that I don't need to execute
printf "sdbst_h256_%s\n" $(echo -n somerandomkeyhere | sha256sum | cut -d' ' -f1)
?
v
no, you don't have to that. That's for an entirely different feature in our commercial products. I'll take that as feedback.
all you have to do is use the same preshared key you specified in your docker instnace
so where you have
bearer_token_credentials
you pass that value
also you cannot use
bearer_token_credentials
if you are talking to
localhost
without TLS. You have to use the insecure transport: https://discord.com/channels/844600078504951838/1257320988312604814/1257325939210059807
z
ok, wait a minute, I'm trying
Copy code
client = Client(
    "xxx:50051",
    insecure_bearer_token_credentials("blabla")
)
will cause error :
Copy code
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.UNAVAILABLE
    details = "failed to connect to all addresses; last error: UNKNOWN: ipv4:10.124.106.121:50051: Endpoint is neither UDS or TCP loopback address."
    debug_error_string = "UNKNOWN:Error received from peer  {created_time:"2024-07-02T08:58:14.0618968+00:00", grpc_status:14, grpc_message:"failed to connect to all addresses; last error: UNKNOWN: ipv4:10.124.106.121:50051: Endpoint is neither UDS or TCP loopback address."}"
>
bearer_token_credentials
will cause the same problem
it will cause another problem:
Copy code
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.PERMISSION_DENIED
    details = "invalid preshared key: invalid token"
    debug_error_string = "UNKNOWN:Error received from peer ipv4:10.124.106.121:50051 {grpc_message:"invalid preshared key: invalid token", grpc_status:7, created_time:"2024-07-02T09:01:20.2423698+00:00"}"
>
I will try java sdk, not sure whether there's bug in python
v
are you calling to a spicedb on localhost, or somewhere that is not localhost (e.g. docker network?)
that's a known bug on python gRPC, and the workaround for now is the gist, yeah
116 Views