Authenticate
The Platform API is served over TLS and authenticated with a bearer token. Coordinate the endpoint and a token for your integration through your Greenroom engagement.
Configure two values, conventionally via environment variables:
| Variable | Meaning |
|---|---|
PLATFORM_ENDPOINT | Host and port of the Platform endpoint, e.g. platform.example.greenroomrobotics.com:443 |
PLATFORM_TOKEN | Bearer token presented on every request |
Open a secure channel that presents the token on each call:
- Python
- C++
- TypeScript
auth.py
import os
import grpc
def create_channel() -> grpc.Channel:
call_creds = grpc.access_token_call_credentials(os.environ["PLATFORM_TOKEN"])
channel_creds = grpc.composite_channel_credentials(
grpc.ssl_channel_credentials(),
call_creds,
)
return grpc.secure_channel(os.environ["PLATFORM_ENDPOINT"], channel_creds)
auth.cc
#include <grpcpp/grpcpp.h>
std::shared_ptr<grpc::Channel> CreateChannel() {
auto call_creds = grpc::AccessTokenCredentials(std::getenv("PLATFORM_TOKEN"));
auto channel_creds = grpc::CompositeChannelCredentials(
grpc::SslCredentials(grpc::SslCredentialsOptions()), call_creds);
return grpc::CreateChannel(std::getenv("PLATFORM_ENDPOINT"), channel_creds);
}
Create a Connect transport that attaches the bearer token to every request:
auth.ts
import { createGrpcTransport } from "@connectrpc/connect-node";
import type { Interceptor } from "@connectrpc/connect";
const auth: Interceptor = (next) => (req) => {
req.header.set("Authorization", `Bearer ${process.env.PLATFORM_TOKEN}`);
return next(req);
};
export const transport = createGrpcTransport({
baseUrl: `https://${process.env.PLATFORM_ENDPOINT}`,
interceptors: [auth],
});
Token expiry and self-signed endpoints
If a token expires or is rejected, calls fail with the gRPC status UNAUTHENTICATED — refresh the
token and rebuild the channel (see Error handling). Connecting
to a vessel on a private network with a self-signed certificate needs extra TLS setup — see
Connecting to a vessel.
Next
Make your first call in the Quickstart.