Skip to content

Commit

Permalink
Change endpoint key
Browse files Browse the repository at this point in the history
From what I can see we have been using the wrong endpoint for logging in. We have been using hte authorization_endpoint, not the token_endpoint. This became clear when testing nikita with keycloak.
Digging a little more into the topic I found the following [description](https://www.ibm.com/docs/en/sva/9.0.5?topic=SSPREK_9.0.5/com.ibm.isam.doc/config/concept/OAuthEndpoints.htm). Here it states that:

_Authorization endpoint_: An authorization URL where the resource owner grants authorization to the OAuth client to access the protected resource. https://server.oauth.com/mga/sps/oauth/oauth20/authorize

_Token endpoint_: A token request URL where the OAuth client exchanges an authorization grant for an access token and an optional refresh token. https://server.oauth.com/mga/sps/oauth/oauth20/token

This commit fixes this, but also changes the way the URL is built for logging in. The old approach of building the URL is not working with keycloak. I believe that the parameters should be in the body. I can't find the description that requires this to be in the body rather than the as query parameters, but the [following](https://connect2id.com/products/server/docs/api/token) is an example that requires the values in the body of a request.
  • Loading branch information
tsodring committed Jul 24, 2023
1 parent d8b51cd commit b8bea71
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/n5core/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def login(self, username = None, password = None):
elif urloidc is not None:
(content, res) = self.json_get(urloidc)
j = json.loads(content)
url = j['authorization_endpoint']
url = j['token_endpoint']
try:
if username is None:
username = '[email protected]'
Expand All @@ -105,8 +105,7 @@ def login(self, username = None, password = None):
key_str = key_bytes.decode('ascii')
self.token = 'Basic {}'.format(key_str)
# Manually encode query parameters in the URL:
updated_url = url + "?" + datastr
(c,r) = self.post(updated_url, None, 'application/x-www-form-urlencoded')
(c,r) = self.post(url, datastr.encode("utf-8"), 'application/x-www-form-urlencoded')
except HTTPError as e:
raise LoginFailure("Posting to login relation %s failed: %s (%s)" % (url, str(e), e.read()))
j = json.loads(c.decode('UTF-8'))
Expand Down

0 comments on commit b8bea71

Please sign in to comment.