berkinet wrote:...I might just get inspired...
Rainy day and I got inspired to play around a bit with Token auth -- on a
very limited scale. I did not check out a copy of the software, preferring, for the moment, to just play locally. This seems manageable since the scope of the changes is quite small.
First, I modified the device somewhat in the authentication section. It struck me the
useAuth checkbox was redundant with the digsetType menu. So, I deleted the useAuth checkbox and renamed the menu item
useAuth. Then I added two entries so the list now contains the values: none, basic, digest or token. I also did a visibleBinding of the authentication data (username, password and token URL) to the value of authType. I think this removes possible confusion.
That made it easy to modify
getTheData so the auth type can now be read directly and the test for auth type becomes
- Code: Select all
auth_type = dev.pluginProps.get('useAuth', "none")
...
if auth_type == 'digest':
...
elif auth_type == 'basic':
...
else:/code]. Since the token acquisition doesn't really use any authentication services I just stuck it in the [i]else[/i] giving [code]else:
if auth_type == 'token':
# We need to get a token to get started
a_url = dev.pluginProps['tokenUrl']
curl_arg = "/usr/bin/curl -vsk -H 'Content-Type: application/json' -X POST --data-binary '{ \"pwd\": \"" + password + "\", \"remember\": 1 }' '} ' " + a_url
proc = subprocess.Popen(curl_arg, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
reply_in = proc.communicate()
reply = simplejson.loads(reply_in[0])
token = (reply["access_token"])
# Now, add the token to the end of the url
url = url + "?access_token=" + token
proc = subprocess.Popen(["curl", '-vsk', url], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Note the single argument for curl passed to
subprocess.Popen. This was because, for the life of me, I could not coerce subprocess.Popen to accept double-hyphen (I.e. GNU type) arguments as individual array elements and I needed to use
--data-binary.