Skip to content

Instantly share code, notes, and snippets.

@marcolarosa
Created November 3, 2021 22:56
Show Gist options
  • Save marcolarosa/58e0903aa5d42d0842a42f29c83bfa7e to your computer and use it in GitHub Desktop.
Save marcolarosa/58e0903aa5d42d0842a42f29c83bfa7e to your computer and use it in GitHub Desktop.
Talking to Reva via node-cs3apis
import { GatewayAPIClient } from "@cs3org/node-cs3apis/cs3/gateway/v1beta1/gateway_api_grpc_pb";
const {
AuthenticateRequest,
WhoAmIRequest,
} = require("@cs3org/node-cs3apis/cs3/gateway/v1beta1/gateway_api_pb")
import {
ListStorageSpacesRequest,
} from "@cs3org/node-cs3apis/cs3/storage/provider/v1beta1/provider_api_pb";
function promisifyAll(client) {
const to = {};
for (var k in client) {
if (typeof client[k] != "function") continue;
to[k] = promisify(client[k].bind(client));
}
return to;
}
// set up connection to reva
let client = new GatewayAPIClient(
"reva-gateway:19000",
grpc.credentials.createInsecure(),
{}
);
let req = new AuthenticateRequest();
req.setType("basic");
req.setClientId(username);
req.setClientSecret(password);
// get promisified versions of the methods we need
const { authenticate, listStorageSpaces, whoAmI } = promisifyAll(client)
// authenticate to reva and get user token
let response = await authenticate(req);
let token = response.getToken();
// perform whoAmI request using token -> WORKS
let req = new WhoAmIRequest();
req.setToken(token);
let whoami = await whoAmI(req);
console.log(whoami);
// perform listStorageSpaces request - FAILS
req = new ListStorageSpacesRequest();
let spaces = await listStorageSpaces(req, { 'x-access-token', token });
console.log(spaces);
--> Fails with error: 'gateway: error listing providers: rpc error: code = Unauthenticated desc = auth: core access token not found'
// Question: How do I set the token for the request?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment