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

[11.0] [FIX] auth_oauth_ip breaks auth_oauth_check_client_id #814

Open
wants to merge 1 commit into
base: 11.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions auth_oauth_ip/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class res_users(models.Model):
_inherit = 'res.users'

def _auth_oauth_rpc(self, endpoint, access_token, local_host=None, local_port=None):
local_host = local_host or self.env.context.get('local_host')
local_port = local_port or self.env.context.get('local_port')
params = werkzeug.url_encode({'access_token': access_token})
host = None
try:
Expand All @@ -39,22 +41,13 @@ def _auth_oauth_rpc(self, endpoint, access_token, local_host=None, local_port=No
else:
url = endpoint + '?' + params
req = urllib.request.Request(url, headers={'host': host})
print(('url', url))

with urllib.request.urlopen(req) as response:
html = response.read()
return json.loads(html.decode("utf-8"))

@api.model
def _auth_oauth_validate(self, provider, access_token):
""" return the validation data corresponding to the access token """
p = self.env['auth.oauth.provider'].browse(provider)
validation = self._auth_oauth_rpc(
p.validation_endpoint, access_token, local_host=p.local_host, local_port=p.local_port)
if validation.get("error"):
raise Exception(validation['error'])
if p.data_endpoint:
data = self._auth_oauth_rpc(
p.data_endpoint, access_token, local_host=p.local_host, local_port=p.local_port)
validation.update(data)
return validation
self = self.with_context(local_host=p.local_host, local_port=p.local_port)
return super(res_users, self)._auth_oauth_validate(provider, access_token)