# 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:** 1\
**Showing post:** 4

<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)
```

---

_[View the full topic](https://forum.inductiveautomation.com/t/oauth2-connections/12366)._
