Skip to content

Commit 23e614b

Browse files
committed
Fix to revocation endpoint
This commit updates the validator (`MyRequestValidator`) object, so the method `authenticate_client`, now is overridden and checks if a client is public before checking if client secrets match. Signed-off-by: Jonas Brunsgaard <jonas.brunsgaard@gmail.com>
1 parent 61622de commit 23e614b

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

models.py

+4
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ class Token(db.Model):
162162
expires = db.Column(db.DateTime)
163163
scopes = ['']
164164

165+
def delete(self):
166+
db.session.delete(self)
167+
db.session.commit()
168+
165169
@staticmethod
166170
def find(access_token=None, refresh_token=None):
167171
""" Retrieve a token record using submitted access token or

requirements.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
Flask
22
Flask-SQLAlchemy
3+
Flask-Oauthlib
34
bcrypt
45
pyOpenSSL
5-
6-
# We need pull #151, which are not in version 0.7.0, thus we get flask-oauthlib
7-
# directly from git.
8-
-e git+https://github.com/lepture/flask-oauthlib.git#egg=flask-oauthlib

validator.py

+28
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# -*- coding: utf-8 -*-
33

44
from flask_oauthlib.provider import OAuth2RequestValidator
5+
from flask_oauthlib.provider.oauth2 import log
6+
from flask_oauthlib.utils import decode_base64
7+
from oauthlib.common import to_unicode
58
from models import User, Client, Token
69

710

@@ -16,3 +19,28 @@ def __init__(self):
1619
self._usergetter = User.find_with_password
1720
self._tokengetter = Token.find
1821
self._tokensetter = Token.save
22+
23+
def authenticate_client(self, request, *args, **kwargs):
24+
25+
auth = request.headers.get('Authorization', None)
26+
if auth:
27+
try:
28+
_, s = auth.split(' ')
29+
client_id, client_secret = decode_base64(s).split(':')
30+
client_id = to_unicode(client_id, 'utf-8')
31+
except Exception as e:
32+
log.debug('Authenticate client failed with exception: %r', e)
33+
return False
34+
else:
35+
client_id = request.client_id
36+
37+
client = self._clientgetter(client_id)
38+
if not client:
39+
log.debug('Authenticate client failed, client not found.')
40+
return False
41+
42+
if client.client_type == 'public':
43+
return self.authenticate_client_id(client_id, request)
44+
else:
45+
return OAuth2RequestValidator.authenticate_client(
46+
self, request, *args, **kwargs)

0 commit comments

Comments
 (0)