[sandstorm] Mobile and Descktop clients can't connect to Sandstorm RC grain
Right now, I can't seem to figure out how to get my local RC client on my Mac to connect to my Sandstorm RC grain. Probably because it isn't possible yet.
@Sing-Li ?
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
Did you try this?

Hey @engelgabriel, that gets me to the prompt to enter a host URL, but I'm not sure what to put into the "host URL."
For instance, I tried using a Share link that would ordinarily be able to open that instance in a new browser window, but I get the error "Not a valid instance url." I also try using the webkey (which is how Sandstorm connects to things like mobile apps). Same error.
I think there's some plumbing underneath that needs to get looked at.
It checks for a specific http header, to make sure it is a RC server. Maybe Sandstorm is removing this unknown header?
We will change from a custom header to a /info rest api
relates to https://github.com/RocketChat/Rocket.Chat.Cordova/issues/26
So is it currently impossible/infeasible to connect the apps to a RC grain on Sandstorm? Any idea on when this might be doable?
We just need a fixed URL to connect to, we have already removed the dependency on custom http headers
@jparyani - can you please describe the magic involved ? You are the only known human living today who had successfully integrated a mobile app into Sandstorm (quoting @kentonv )
By "fixed URL" do you mean a URL that doesn't change, or that something needs to be fixed before it'll work? :)
I've already tried pointing the server to the underlying subdomain SS creates for the grain, but that just hands back Unauthorized errors.
@nathanhourt The subdomains that Sandstorm creates are ephemeral (they only last as long as your web browser is open to that tab), and as you saw, they check for a cookie that is only given to the client that created that session.
Sandstorm requires api access to go through a webkey (see https://docs.sandstorm.io/en/latest/developing/http-apis/#about-webkeys). Further up on that page, it shows you how to add an offer template to your app, which is our recommended way of displaying to users how to set this up. If you don't add an offer template, users can still generate a webkey manually through the Sandstorm UI by clicking the key icon.
The one thing that Rocket.Chat mobile apps will probably have to change is to handle how authorization with webkeys works. An example webkey is https://alpha-api.sandstorm.io#49Np9sqkYV4g_FpOQk1p0j1yJlvoHrZm9SVhQt7H2-9. The part after the # is a bearer token that needs to be sent as an authorization header. For example, a curl statement accessing the webkey above would look like:
curl -H "Authorization: Bearer 49Np9sqkYV4g_FpOQk1p0j1yJlvoHrZm9SVhQt7H2-9" https://alpha-
api.sandstorm.io
@jparyani the mobile app doesn't use any APIs, it is just a webview :) We just need access to the webapp itself without the sandstrom "wrapper". Is that possible in any way?
In theory your "API" could just serve up regular web content. There are a couple quirks, though.
Sandstorm generally does not want apps hosting web content at a fixed URL for security reasons: Our sandboxing, and our added CSRF defense, depend on randomized per-session hostnames. APIs, however, obviously must have a fixed location, so we have the API endpoint for that. But, since we don't want regular web browsers rendering HTML content from our API endpoint (since it would defeat our sandboxing), we require the Authorization: bearer header (which web browsers never send for a normal browsing context) and we serve the content with headers like Content-Security-Policy and Content-Disposition to try to convince browsers that they absolutely should not render HTML from this endpoint. We also drop all cookies.
Now, if you have a mobile app that is just a webview locked to the rocket.chat server, then arguably it's OK for you to bypass Sandstorm's sandboxing -- or more accurately, it is your app's responsibility to implement any sandbox, not Sandstorm's, because your app is not hosted by Sandstorm. Crucially, though, your app's webview should not be rendering any other sites and should not be sharing a cookie jar with the user's main web browser.
In this scenario, what your app can perhaps do is fetch web content directly from the API endpoint and pass it to the WebView with the following modifications:
- Add the appropriate Authorization header to all requests, as described above.
- Strip off the Content-Security-Policy and Content-Disposition headers before passing along to the webview.
- Do NOT allow the WebView or any nested iframe to browse to any third-party host, unless you are confident you've mitigated the CSRF risks somehow. It's probably better to open the user's regular web browser instead.
Despite the long explanation, I think the above should be easy to implement? I suggest triggering all this specifically when the user enters a webkey as the host -- i.e. a URL that contains a # character as described above.
Hi ! I'm also interested ! ;)
I propose a hackathon of the Sandtorm and Rocket.Chat teams to get this working :)
...and I'm offering the reward cookies ;)
+1 for this!
Is anyone on the Rocket.Chat side working on this? How can we help?
How can we get the API endpoint? The user is expected to type that URL on the desktop/mobile client login form?
Found this:


OK, so:
https://api.oasis.sandstorm.io#R75AxS08WI_MLEks27sn0kyDOGEVqVPjN97KWudxA8H
should result on a request like this:
curl -i https://api.oasis.sandstorm.io -H "Authorization: Bearer R75AxS08WI_MLEks27sn0kyDOGEVqVPjN97KWudxA8H"
that gave me our index html indeed...