Skip to content

Commit 072185e

Browse files
committed
add servers params. SWAGGER-UI password impl is broken
+ # TODO: Because SWAGGER-UI password-flow doesn't follow the oauth2 RFC it needs location='form' for it to work. + # Rewrite is being discussed in swagger-api/swagger-ui#3227 + # https://www.oauth.com/oauth2-servers/access-tokens/password-grant/
1 parent 6d09078 commit 072185e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

app/apis/auth.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ def sanitize_fields(self, item):
6767
item['username'] = item['username'].lower().strip()
6868
return item
6969

70-
@blp.arguments(TokenSchema, location='form')
70+
# TODO: Because SWAGGER-UI password-flow doesn't follow the oauth2 RFC it needs location='form' for it to work.
71+
# Rewrite is being discussed in https://github.com/swagger-api/swagger-ui/issues/3227
72+
# https://www.oauth.com/oauth2-servers/access-tokens/password-grant/
73+
@blp.arguments(TokenSchema, location='json')
7174
@response_error(Unauthorized('Invalid credentials'))
7275
@blp.response(UserCredentialsSchema)
7376
def post(self, login_payload):

app/app.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
from apis.corpora import blp as corpora
1212
from apis.users import blp as users
1313

14-
1514
app = Flask('NERd')
15+
app.config['PREFERRED_URL_SCHEME'] = os.environ.get('NERD_URL_SCHEME', 'http')
16+
app.config['SERVER_NAME'] = os.environ.get('NERD_SERVER_NAME', '127.0.0.1:5000')
1617

1718
mongoengine.connect(
1819
db=os.environ.get('NERD_MONGO_DB_NAME', 'nerd'),
@@ -37,6 +38,13 @@
3738
app.config['OPENAPI_SWAGGER_UI_VERSION'] = '3.21.0'
3839
app.config['API_VERSION'] = '1.0.0'
3940
app.config['API_SPEC_OPTIONS'] = {
41+
'servers': [{
42+
'url': '{}://{}'.format(
43+
app.config['PREFERRED_URL_SCHEME'],
44+
app.config['SERVER_NAME']
45+
),
46+
'description': 'Default api endpoint'
47+
}],
4048
'components': {
4149
'securitySchemes': {
4250
'oAuth2Password': {

0 commit comments

Comments
 (0)