OAuth2 connections

I have been trying to interface with a 3rd party vendor that stores data in a cloud environment and uses an OAuth2.0 based authentication to pull data from their site. I’ve been trying to find a way to write a gateway script to pull this data, but I haven’t had any luck. The libraries I have found that allow OAuth2 communications all appear to require at least Python 2.6, and when I add them to the user library, I’m not able to link to them due to one error or another. Anybody have any advice on what else to try? I know that Google and Facebook both use OAuth2.0 for access to their site.

It does not look like there are any oAuth v2.0 Python libraries that will work with Python 2.5.
Because Ignition actually uses Jython, you get to also take advantage of Java libraries, so you may want to look into those. The caveat is that the only officially supported way of getting those into Ignition is via a module; unofficially though, JARs can be placed in certain directories to make them available (see Kevin’s response https://inductiveautomation.com/forum/viewtopic.php?f=70&t=14757&p=54213 )

If you are interested in pursuing the Java route, you may want to review this: inductiveautomation.com/forum/v … 57&p=54213

Hi, I have a similar need. Did you develop a solution for using OAuth1?

I was able to get it to work, but it’s unclear to me whether I used OAuth, or another feature that’s unique to this vendor. I followed some sample code from them using Curl and translated it to Jython. Below is the code in my script that contacts the server to retrieve the data. Not sure if this works for any site other than the one I’m working with.

username = ‘username’
password = ‘password’
ClientID = ‘xxx’
ClientSecret = ‘xxx’
AccessToken = system.tag.read(“AccessToken”).value
headers = {“Content-Type”:“application/json”, “Authorization”:"Bearer "+AccessToken}
MeterBase = “https://site/
Modifiers = “/data?format=json&resolution=”

response = system.net.httpGet(MeterBase+MeterID+Modifiers, headerValues = headers)
response = system.net.httpPost(“https://site.com/o/token/”, {“client_id”:ClientID, “client_secret”:ClientSecret, “username”:username, “password”:password, “grant_type”:“password”})
PyResponse = system.util.jsonDecode(response)

AccessToken = PyResponse["access_token"]
RefreshToken = PyResponse["refresh_token"]

system.tag.write("AccessToken", AccessToken)
system.tag.write("RefreshToken", RefreshToken)
headers = {"Content-Type":"application/json", "Authorization":"Bearer "+AccessToken}
response = system.net.httpGet(MeterBase+MeterID+Modifiers, headerValues = headers)

Interesting. I think I’m going to write some “middleman” scripts in Python3 that take handoffs from Ignition outputs and run the queries against the 3rd party RESTlet API. If I had to do big complex stuff this would be messy, but I’m just trying to sync certain types of info across the two systems.