From 765c8c7ccb5aa49e78861b0b8dd8487fe4da284e Mon Sep 17 00:00:00 2001
From: Mats Blomdahl <mats.blomdahl@gmail.com>
Date: Thu, 2 Nov 2017 16:01:42 +0100
Subject: [PATCH 1/3] Bump patch version + changelog update

---
 README.rst             | 7 +++++++
 package-lock.json      | 2 +-
 package.json           | 2 +-
 xl_auth/oauth/views.py | 1 -
 4 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/README.rst b/README.rst
index 5a673e27..6022ba09 100644
--- a/README.rst
+++ b/README.rst
@@ -183,6 +183,13 @@ DB Models
 Changelog
 =========
 
+v. 0.5.3
+--------
+
+* Add collection name to ``/oauth/verify`` response
+* Fix broken database migration (`#68 <https://github.com/libris/xl_auth/issues/68>`_)
+
+
 v. 0.5.2
 --------
 
diff --git a/package-lock.json b/package-lock.json
index 302b4eec..a5367e11 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
   "name": "xl_auth",
-  "version": "0.5.2",
+  "version": "0.5.3",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
diff --git a/package.json b/package.json
index 8e700e93..28e53c14 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "xl_auth",
-  "version": "0.5.2",
+  "version": "0.5.3",
   "author": "National Library of Sweden",
   "license": "Apache-2.0",
   "description": "OAuth2 authorization for LibrisXL, replacing BibDB counterpart",
diff --git a/xl_auth/oauth/views.py b/xl_auth/oauth/views.py
index 36e214e3..4972c75f 100644
--- a/xl_auth/oauth/views.py
+++ b/xl_auth/oauth/views.py
@@ -85,7 +85,6 @@ def require_oauth_invalid(req):
 
 @blueprint.route('/authorize', methods=['GET', 'POST'])
 @login_required
-@oauth_provider.authorize_handler
 def authorize(*_, **kwargs):
     """OAuth2'orize."""
     authorize_form = AuthorizeForm(request.form)

From 153b856d6456b58fdf7f3a033a01220ac987004c Mon Sep 17 00:00:00 2001
From: Mats Blomdahl <mats.blomdahl@gmail.com>
Date: Thu, 2 Nov 2017 16:02:37 +0100
Subject: [PATCH 2/3] #68 Fix broken Alembic migration

---
 migrations/versions/22069cad6602_restructure_oauth2_models.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/migrations/versions/22069cad6602_restructure_oauth2_models.py b/migrations/versions/22069cad6602_restructure_oauth2_models.py
index a2a1ecd8..4ea3fc9e 100644
--- a/migrations/versions/22069cad6602_restructure_oauth2_models.py
+++ b/migrations/versions/22069cad6602_restructure_oauth2_models.py
@@ -20,9 +20,9 @@
 
 def upgrade():
     """Re-create tables 'clients', 'grants' and 'tokens'."""
-    op.drop_table('clients')
     op.drop_table('tokens')
     op.drop_table('grants')
+    op.drop_table('clients')
 
     op.create_table(
         'clients',

From 66478fdfcdf638368f45c39006e8e431e5181b96 Mon Sep 17 00:00:00 2001
From: Mats Blomdahl <mats.blomdahl@gmail.com>
Date: Thu, 2 Nov 2017 16:10:57 +0100
Subject: [PATCH 3/3] #68 Return collections friendly names from
 `/oauth/verify`

---
 tests/end2end/test_oauth.py | 2 ++
 xl_auth/oauth/views.py      | 2 ++
 xl_auth/settings.py         | 1 +
 3 files changed, 5 insertions(+)

diff --git a/tests/end2end/test_oauth.py b/tests/end2end/test_oauth.py
index ee31c3a0..bf8a022d 100644
--- a/tests/end2end/test_oauth.py
+++ b/tests/end2end/test_oauth.py
@@ -154,9 +154,11 @@ def test_verify_success_response(token, testapp):
         if permission['code'] == permission1.collection.code:
             assert permission['registrant'] is True
             assert permission['cataloger'] is False
+            assert permission['friendly_name'] == permission1.collection.friendly_name
         if permission['code'] == permission2.collection.code:
             assert permission['registrant'] is False
             assert permission['cataloger'] is True
+            assert permission['friendly_name'] == permission2.collection.friendly_name
 
 
 def test_verify_without_bearer(testapp):
diff --git a/xl_auth/oauth/views.py b/xl_auth/oauth/views.py
index 4972c75f..85048ad1 100644
--- a/xl_auth/oauth/views.py
+++ b/xl_auth/oauth/views.py
@@ -85,6 +85,7 @@ def require_oauth_invalid(req):
 
 @blueprint.route('/authorize', methods=['GET', 'POST'])
 @login_required
+@oauth_provider.authorize_handler
 def authorize(*_, **kwargs):
     """OAuth2'orize."""
     authorize_form = AuthorizeForm(request.form)
@@ -120,6 +121,7 @@ def verify():
             'full_name': oauth.user.full_name,
             'email': oauth.user.email,
             'permissions': [{'code': permission.collection.code,
+                             'friendly_name': permission.collection.friendly_name,
                              'cataloger': permission.cataloger,
                              'registrant': permission.registrant}
                             for permission in oauth.user.permissions]
diff --git a/xl_auth/settings.py b/xl_auth/settings.py
index 3da13c04..9bf09f2b 100644
--- a/xl_auth/settings.py
+++ b/xl_auth/settings.py
@@ -14,6 +14,7 @@ class Config(object):
     APP_NAME = __name__
     APP_VERSION = __version__
     APP_AUTHOR = __author__
+    JSON_AS_ASCII = False
     SECRET_KEY = os.environ.get('XL_AUTH_SECRET', 'secret-key')  # TODO: Change me
     APP_DIR = os.path.abspath(os.path.dirname(__file__))  # This directory.
     PROJECT_ROOT = os.path.abspath(os.path.join(APP_DIR, os.pardir))