Oauth URL

I am trying to port a Smartthings app to Hubitat.
The app is using oauth which I really don't understand.
I thought maybe bu just modifying the oauth url, I could try.
But I don't know the correct URL for hubitat.

Any ideas on this ? Below is the part of the app that the URLs are defined:

def getServerUrl()           { return "https://graph.api.smartthings.com" }
def getShardUrl()            { return getApiServerUrl() }
def getCallbackUrl()         { return "https://graph.api.smartthings.com/oauth/callback" }
def getBuildRedirectUrl()    { return "${serverUrl}/oauth/initialize?appId=${app.id}&access_token=${atomicState.accessToken}&apiServerUrl=${shardUrl}" }

on another thread I found the following url:
https://oauth.cloud.hubitat.com

but that did not work.

Do you just need a local or cloud OAuth endpoint from the app to work with, or are you trying to integrate the authentication with someone else's web-based login/auth flow? If all you need is an endpoint, those are built-in, and you can find the documented in Hubitat's app methods. The biggest difference beyond that is that Hubitat offers both local and cloud endpoints. I'd use local when you can:

https://docs.hubitat.com/index.php?title=App_Object#Provided_Methods

First, you'd need to call createAccessToken(), which should create state.accessToken. The return values of the built-in methods like getLocalApiServerUrl() or getFullLocalApiServerUrl, documented above, should then take care of the rest of what you need. Beyond that, it's hard to help without seeing how the methods above are actually being used in the ST SmartApp...and it's been so long that I'm not sure how much help I'd be even if I did see there anymore. :rofl: (But I don't think this will quite be a find-and-replace job if you're not familiar with development on either platform.)

EDIT: And if you do need a "flow," this document is probably the one you're looking for (and is probably a better explanation even if you don't than mine above):

https://docs.hubitat.com/index.php?title=App_OAuth

1 Like

thx.

ST app I'm trying to port is the Neato Connect app. Actually I am surprised to see that nobody else has ported it or created an alternative one for Hubitat.

I've stucked at:

def getBuildRedirectUrl() { return "${serverUrl}/oauth/initialize?appId=${app.id}&access_token=${atomicState.accessToken}&apiServerUrl=${shardUrl}" }

this is just for getting the build version of the app.
Maybe I should just cut that part, but I don't know what "redirectUrl" is being used for. It is referenced several times in the code.

do you understand what the above URL returns from ST cloud ?

btw, I see that there is a good oauth mechanism which works with either local call or cloud call in Hubitat. But trying to understand how it works is a lot beyond me.
I've lost features on ST hub and migrating to Hubitat as quickly as possible.
That's why I don't have much time to study developer documentation.
I had thought that since this app is just talking to Neato cloud, it should not depend much on ST features.
Am I wrong ?

Looks like there's a version someone is maintaining here:

no it's not :frowning:

this is netatmo; what I'm working on is "neato"
one is a thermostat, the other is a vacum robot

1 Like

Ha, amazing what one letter can do... :rofl: (Though it should be noted that Netatmo makes other products too and was on my mind because I have one.)

I see some discussion of that but no actual port. If your attempts don't work out, you could use the "virtual switch" workaround with Alexa, since it looks like it has an Alexa integration: create a virtual motion or contact sensor (or two) in Hubitat, expose it to Alexa, then create an Alexa Routine that does whatever you want in response to the virtual sensor becoming active/open or whatnot (a virtual switch or button would be more intuitive, but Alexa does not support using those as "triggers" for routines). That won't get you status from the device into Hubitat, but it's something.

Otherwise, I'm afraid I won't be much help beyond the general advice and docs above since I don't have one of these.

actually, Alexa integration is not good and I was using the smart app & driver to achieve an enhanced integration.

well, there is a working code for ST and like I said it is mostly communicating with Neato cloud.
so it should be easily convertible.

I just need to understand what the ST cloud oauth is used for and make a replacement for it which works on Hubitat.

Any idea what this call is for ?
def getBuildRedirectUrl() { return "${serverUrl}/oauth/initialize?appId=${app.id}&access_token=${atomicState.accessToken}&apiServerUrl=${shardUrl}" }

what it might from ST api ?

If you have it set up on ST, I should mention that you can use HubConnect to integrate any supported capabilites into Hubitat--at least for as long as ST's "classic" Groovy IDE stays around. That is, assuming you don't like workarounds/integrations with Alexa, IFTTT, or whatever other options there may be.

I'm not sure how cloud-based OAuth flow worked on ST, and I've only used local on Hubitat (and not super "flow"-y...basically manually pasting keys), so you've probably reached the limits of what I know how to help with. :slight_smile: Perhaps someone else will see this thread and know how to assist. In the meantime, if it's helpful for you, I did find this other thread where OAuth with a third-party cloud was discussed, similar to what you're doing. You may find it helpful:

(I know, I know, by coincidence, it also deals with Netatmo, but the idea should be similar for either.)

1 Like

thanks, I will check that.

I know about the HubCOnnect app , but that's not the ideal way. Because I'm trying to migrate everything and get rid of the ST hub.

I will try to read more on Hubitat Oauth and possibly make tests with what ST returns to that call.
Then maybe your example could help me...

This looks like a cloud device, not LAN (and definitely not Z-Wave or Zigbee), so you technically wouldn't really need the ST hub running for it to work, and HubConnect 2.x doesn't even require a physical ST hub to set things up (just a location/hub in your ST account as you need for anything else). So, I wouldn't dismiss that right away. But, I agree that it's not ideal...though neither, I suppose, are cloud-first devices like this in general. :smiley: Hope you get something figured out!

1 Like

I've studied this a little.
Made several changes looking at the Netatmo example.

Coming to the end of the tunnel , but I have an issue:

on the original Neato app, the oauthInitUrl() function forms the URL to connect to the Neato API.
then it uses the redirect() command to pass the URL:

redirect(location: "${apiEndpoint}/oauth2/authorize?${toQueryString(oauthParams)}")

normally , it has a mapping which calls oauthInitUrl() when /oauth/initialize is called.

mappings {
    path("/oauth/initialize") {action: [GET: "oauthInitUrl"]}
    path("/oauth/callback") {action: [GET: "callback"]}
}

so the redirect() command is useful here.
But on Hubitat , there is no "redirect()" command.
it is advised to return the URL as string from oauthInitUrl() , like:

return "${apiEndpoint}/oauth2/authorize?${toQueryString(oauthParams)}"

on Netatmo this is usefull because oauthInitUrl() is called from dynamic page:

href url:oauthInitUrl(), external:true, required:false, title:"Connect to ${getVendorName()}:", description:description

Since, on the Neato app this is not the flow, I have to find a way to make a call to the URL at the end of the oauthInitUrl() function, OR a mapping which will call the returned URL directly here:

path("/oauth/initialize") {action: [GET: "oauthInitUrl"]}

which one is possible on Hubitat ?

well, I solved that issue.
now Neato API asks me for a redirect_uri

but it changes each time I create a new app.
https://cloud.hubitat.com/api/49dc9212-0b7a-4ad9-99bb-acfb420b61f2/apps/168/oauth/callback

or

https://cloud.hubitat.com/api/49dc9212-0b7a-4ad9-99bb-acfb420b61f2/apps/169/oauth/callback

would it be possible to use wildcards in the redirect_uri ?

I would just use the app.id property in your string instead of hardcoding it.

but that is sent to Neato API and it will return this back.
how shall my browser go to correct app id ?

I have to put in a "redirect_uri" to Neato api account
how can I write it parametric ?
and then how can I send it parametric ?

Oh, wait, is that entirely on the Neato side of things? If you're passing the URL from Hubitat, you could include the app ID (which, again, you can get from the app.id property) in whatever you pass to it. If it's entirely on the Neato side, I don't know. But if the app is only for your own use (or you write good instructions for others), I suppose manually pasting/typing it into that side would still work. You can see the app ID easily in the URL for the Hubitat app when you're "in" the app (after installing it, for example), as you've probably figured out.

quick question: does Hubitat allow adding a child device to a "device" ?
on SMartthings that was possible , but on Hubitat it gives me an error (no signature of method)

It does. Make sure you are using one of the supported methods, however, as I believe the parameters are different from ST: Driver Object - Hubitat Documentation

well, actually noticed the difference between ST and HE addChildDevice commands, and I used it with correct parameters.
However it gave me a missing method exception.

then I called the same command from parent app and it worked.
So, I was able to create child device under the app, but not under the device.