my-devices/sdk

How to generate WebTunnel Configuration file automatically?

thasin96 opened this issue · 9 comments

Hi Team,
I am using Macchina Remote Manager to connect my devices and access those on cloud. To register device I am downloading configuration file on Macchina Device Dashboard. Is there any way I can automate this downloading file by hitting API? or How to generate this file by my own?

You can either create your own configuration file, based on an existing one (e.g., the default one included in the SDK, or one generated via the web interface). See the WebTunnelAgent documentation for a list of supported configuration properties.

The Remote Manager server also provides an API endpoint to generate a configuration file, which is useful for automatic device provisioning. See the documentation page in the Wiki for more information.

@obiltschnig - Thanks for the answer. I am able to create my own configuration file but currently Hardcoding domain_id value. Is there any way I can get domain_id of my account from API?

Yes, there is a separate API for user accounts and permission management. To get information for your account:

curl --user demo@macchina.io:s3cr3t https://reflector.my-devices.net/my-devices/api/users/demo@macchina.io

You'll get back a JSON object that includes a list of user attributes, including the domain:

{
	"attributes":
	[
		{
			"name": "domain",
			"value": "c60a3001-05ae-4dd6-a4fa-2ab692a1123f"
		},
...

It's also possible to query the domain specifically:

curl --user demo@macchina.io:s3cr3t https://reflector.my-devices.net/my-devices/api/users/demo@macchina.io/attributes/domain

This will return the domain as a JSON string (quoted):

"c60a3001-05ae-4dd6-a4fa-2ab692a1123f"

Full documentation for the accounts and permission management API is available upon request (please use our contact form).

awesome, thanks.

@obiltschnig - The suggested APIs return
{
"error": "No permission",
"detail": "user xxx@yyy.com is not authorized to access users",
"code": 0
}

How to resolve this issue?

Make sure the username used for authentication is the same one as in the request path.

@obiltschnig - yeah After updating the suggested change, I am able to get details. I have one more question, I want to integrate macchina in my application. Once device is active, to access connected Http web server I am hitting this url format https://device-id.my-devices.net/. IS there any I can make this link as public. Because, My application already has authentication and I don't wan to redirect my user to Macchina UI to enter username and password. Is there any solution for this issue?

Yes, there is a solution, but it will require you to set up your own Remote Manager server. You will need to synchronize user accounts between your application and Remote Manager. It's then possible to use the API to generate a token for a specific user account, log the user in with that token and redirect to the device with one request.

Basically your application would have a new endpoint for redirecting to the device website. When you get a request for this endpoint, you obtain a token for the user via the Remote Manager API. Then you send back a 303 redirect response to the following URL:

https://reflector.my-devices.net?action=login&jwt=<token>&onsuccess=https://<device>.my-devices.net

Make sure to properly encode the query parameters, specifically the URL passed on onsuccess.

The URL of the server would have to be changed to the one for your own server.

@obiltschnig - We have setup our own Remote Manager server. Could you elaborate the above solution in detail? so that we will
proceed further?