Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a channel with Python #1024

Closed
aswanevelder opened this issue Apr 21, 2019 · 3 comments
Closed

Creating a channel with Python #1024

aswanevelder opened this issue Apr 21, 2019 · 3 comments

Comments

@aswanevelder
Copy link

I am unable to authenticate the token, any advice will be greatly appreciated. Printing the output from the GET /channels, I get an Unauthorized.

import sys, json, requests, hashlib

r = requests.get('https://localhost:8082/authenticate/root@openhim.org', verify=False)
openauth = r.json()
print(openauth)

j = json.dumps(openauth)
salt = json.loads(j)["salt"]
print(salt)
ts = json.loads(j)["ts"]
print(ts)

passwordhash = hashlib.sha512(str(salt+'openhim-password').encode('utf-8'))
print(passwordhash.hexdigest())

authtoken = hashlib.sha512(str(passwordhash.hexdigest()+salt+ts).encode('utf-8'))
print(authtoken.hexdigest())

url = 'https://localhost:8082/channels'
params = {'auth-username':'root@openhim.org','auth-ts':ts,'auth-salt':salt,'auth-token':authtoken.hexdigest()}
chn = requests.get(url, params=params, verify=False)
print(chn.text)

@BMartinos
Copy link
Collaborator

Hi @aswanevelder

Are you able to authenticate to the API on any of the other endpoints or is this endpoint the only one giving this authentication issue?

Are you running the core manually, or using the docker container? and which version

@aswanevelder
Copy link
Author

aswanevelder commented Apr 23, 2019 via email

@BMartinos
Copy link
Collaborator

Hi @aswanevelder

It seems that you arent generating your auth-token correctly. This could also be due to the server timestamp difference that is invalidating the token.

Have a look at how we currently do if from the console side of things
https://github.com/jembi/openhim-console/blob/master/app/scripts/services/authinterceptor.js#L18-L43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants