|
28 | 28 | import pkg_resources |
29 | 29 | from logging.config import dictConfig |
30 | 30 |
|
31 | | -from flask import Flask |
| 31 | +from flask import Flask, render_template |
32 | 32 | from flask_sqlalchemy import SQLAlchemy |
33 | 33 | from flask_migrate import Migrate |
34 | 34 | from flask_marshmallow import Marshmallow |
@@ -105,9 +105,10 @@ def create_app(config_override=None, instance_path=None): |
105 | 105 | app.config.setdefault('OPENAPI_REDOC_URL', 'https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js') |
106 | 106 | app.config.setdefault('OPENAPI_RAPIDOC_PATH', 'rapidoc') |
107 | 107 | app.config.setdefault('OPENAPI_RAPIDOC_URL', 'https://unpkg.com/rapidoc/dist/rapidoc-min.js') |
108 | | - #app.config.setdefault('OPENAPI_SWAGGER_UI_CONFIG', { |
109 | | - # 'oauth2RedirectUrl': 'http://localhost:5000/apidoc/swagger/oauth2-redirect' |
110 | | - #}) |
| 108 | + app.config.setdefault('OPENAPI_SWAGGER_UI_CONFIG', { |
| 109 | + 'oauth2RedirectUrl': 'http://localhost:5000/apidoc/swagger/oauth2-redirect' |
| 110 | + }) |
| 111 | + app.config.setdefault('OPENAPI_SWAGGER_UI_ENABLE_OAUTH', True) |
111 | 112 | if 'FLASK_CONFIG' in os.environ and os.path.exists(os.path.expanduser(os.environ['FLASK_CONFIG'])): |
112 | 113 | app.config.from_json(os.path.expanduser(os.environ['FLASK_CONFIG'])) |
113 | 114 | if config_override is not None: |
@@ -156,31 +157,39 @@ def create_app(config_override=None, instance_path=None): |
156 | 157 | # |
157 | 158 | # If OAuth2 is in use, register our usage |
158 | 159 |
|
159 | | - api.spec.components.security_scheme('mrmat_keycloak', |
160 | | - {'type': 'oauth2', |
161 | | - 'description': 'This API uses OAuth 2', |
162 | | - 'flows': { |
163 | | - 'clientCredentials': { |
164 | | - 'tokenUrl': 'https://keycloak.mrmat.org/auth/realms/master/protocol/openid-connect/token', |
165 | | - 'scopes': { |
166 | | - 'mrmat-python-api-flask-resource-read': 'Allows reading objects ' |
167 | | - 'in the Resource API', |
168 | | - 'mrmat-python-api-flask-resource-write': 'Allows creating/modifying' |
169 | | - ' and deleting objects ' |
170 | | - 'in the Resource API' |
171 | | - } |
172 | | - }, |
173 | | - 'authorizationCode': { |
174 | | - 'authorizationUrl': 'https://keycloak.mrmat.org/auth/realms/master/protocol/openid-connect/auth', |
175 | | - 'tokenUrl': 'https://keycloak.mrmat.org/auth/realms/master/protocol/openid-connect/token', |
176 | | - 'scopes': { |
177 | | - 'mrmat-python-api-flask-resource-read': 'Allows reading objects ' |
178 | | - 'in the Resource API', |
179 | | - 'mrmat-python-api-flask-resource-write': 'Allows creating/modifying' |
180 | | - ' and deleting objects ' |
181 | | - 'in the Resource API' |
182 | | - } |
183 | | - } |
184 | | - }}) |
| 160 | + api.spec.components.security_scheme('mrmat_keycloak', { |
| 161 | + 'type': 'oauth2', |
| 162 | + 'flows': { |
| 163 | + 'authorizationCode': { |
| 164 | + 'authorizationUrl': 'https://keycloak.mrmat.org/auth/realms/master/protocol/openid-connect/auth', |
| 165 | + 'tokenUrl': 'https://keycloak.mrmat.org/auth/realms/master/protocol/openid-connect/token', |
| 166 | + 'scopes': { |
| 167 | + 'openid': 'Basic token without extra authorisation', |
| 168 | + 'mrmat-python-api-flask-resource-read': 'Allows reading objects ' |
| 169 | + 'in the Resource API', |
| 170 | + 'mrmat-python-api-flask-resource-write': 'Allows creating/modifying' |
| 171 | + ' and deleting objects ' |
| 172 | + 'in the Resource API' |
| 173 | + } |
| 174 | + } |
| 175 | + }}) |
| 176 | + # api.spec.components.security_scheme('mrmat_keycloak', { |
| 177 | + # 'type': 'openIdConnect', |
| 178 | + # 'openIdConnectUrl': 'https://keycloak.mrmat.org/auth/realms/master/.well-known/openid-configuration' |
| 179 | + # }) |
| 180 | + # api.spec.security('mrmat_keycloak', [ |
| 181 | + # 'profile', |
| 182 | + # 'mrmat-python-api-flask-resource-write', |
| 183 | + # 'mrmat-python-api-flask-resource-read' |
| 184 | + # ]) |
| 185 | + |
| 186 | + @app.route('/apidoc/swagger/oauth2-redirect') |
| 187 | + def oauth2_redirect(): |
| 188 | + return render_template('swagger-ui-redirect.html') |
| 189 | + # state = request.args.get('state') |
| 190 | + # code = request.args.get('code') |
| 191 | + # session_state = request.args.get('session_state') |
| 192 | + # return {'state': state, 'code': code, 'session_state': session_state}, 200 |
| 193 | + |
185 | 194 |
|
186 | 195 | return app |
0 commit comments