Skip to content

Commit 4fd6943

Browse files
authored
Fix failing Elixir AAI token refresh
Refreshing Elixir AAI tokens fails with error `An error occurred when refreshing user token: 401 Client Error: 401 for url: https://login.elixir-czech.org/oidc/token`. The source of the HTTP 401 error is a malformed request. social-auth-core is sending this sort of request (a few headers are omitted) ``` POST /oidc/token HTTP/1.1 Host: login.elixir-czech.org Accept: application/json Content-Type: application/x-www-form-urlencoded Content-Length: *** {"grant_type": "refresh_token", "refresh_token": "******", "client_id": "******", "client_secret": "******"} ``` and getting this sort of response (again some headers are omitted). ``` HTTP/1.1 401 401 Content-Type: application/json {"error":"invalid_client","error_description":"Bad client credentials"} ``` If the requests are modified so that they look like it is described in RFC6749 (https://datatracker.ietf.org/doc/html/rfc6749#section-2.3.1) ``` POST /oidc/token HTTP/1.1 Host: login.elixir-czech.org Accept: application/json Content-Type: application/x-www-form-urlencoded Content-Length: *** grant_type=refresh_token&refresh_token=******&client_id=******&client_secret=****** ``` then everything works smoothly.
1 parent fd7dd90 commit 4fd6943

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

social_core/backends/elixir.py

+11
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,14 @@ def get_user_details(self, response):
3232
"first_name": first_name,
3333
"last_name": last_name,
3434
}
35+
36+
def refresh_token(self, token, *args, **kwargs):
37+
params = "&".join(
38+
f"{param}={value}"
39+
for param, value in self.refresh_token_params(token, *args, **kwargs).items()
40+
)
41+
url = self.refresh_token_url()
42+
method = self.REFRESH_TOKEN_METHOD
43+
key = "params" if method == "GET" else "data"
44+
request_args = {"headers": self.auth_headers(), "method": method, key: params}
45+
return self.process_refresh_token_response(request, *args, **kwargs)

0 commit comments

Comments
 (0)