# OAuth2 connections

**URL:** <https://forum.inductiveautomation.com/t/oauth2-connections/12366>\
**Category:** Ignition\
**Created:** [November 16, 2016, 6:06pm UTC](https://forum.inductiveautomation.com/t/oauth2-connections/12366 "2016-11-16T18:06:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![d3h637](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@d3h637](https://forum.inductiveautomation.com/u/d3h637)\
**Post date:** [November 16, 2016, 6:06pm UTC](https://forum.inductiveautomation.com/t/oauth2-connections/12366/1 "2016-11-16T18:06:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anna](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@anna](https://forum.inductiveautomation.com/u/anna)\
**Post date:** [March 17, 2017, 10:49pm UTC](https://forum.inductiveautomation.com/t/oauth2-connections/12366/2 "2017-03-17T22:49:01Z")

</div>

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](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](https://inductiveautomation.com/forum/viewtopic.php?f=70&t=14757&p=54213)

---

<div class="post-metadata">

**Author:** ![ctonge](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@ctonge](https://forum.inductiveautomation.com/u/ctonge)\
**Post date:** [May 17, 2017, 3:05pm UTC](https://forum.inductiveautomation.com/t/oauth2-connections/12366/3 "2017-05-17T15:05:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![d3h637](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@d3h637](https://forum.inductiveautomation.com/u/d3h637)\
**Post date:** [May 17, 2017, 3:37pm UTC](https://forum.inductiveautomation.com/t/oauth2-connections/12366/4 "2017-05-17T15:37:47Z")

</div>

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/](https://site/)”  
Modifiers = “/data?format=json&resolution=”

try:  
response = system.net.httpGet(MeterBase+MeterID+Modifiers, headerValues = headers)  
except:  
response = system.net.httpPost(“[https://site.com/o/token/](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)
```

---

<div class="post-metadata">

**Author:** ![ctonge](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@ctonge](https://forum.inductiveautomation.com/u/ctonge)\
**Post date:** [May 17, 2017, 4:28pm UTC](https://forum.inductiveautomation.com/t/oauth2-connections/12366/5 "2017-05-17T16:28:24Z")

</div>

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.
