Created
November 3, 2021 22:56
-
-
Save marcolarosa/58e0903aa5d42d0842a42f29c83bfa7e to your computer and use it in GitHub Desktop.
Talking to Reva via node-cs3apis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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