Skip to content

Support customizing operation security and security schemes#232

Merged
greyli merged 1 commit intomainfrom
auth-lib
Apr 5, 2022
Merged

Support customizing operation security and security schemes#232
greyli merged 1 commit intomainfrom
auth-lib

Conversation

@greyli
Copy link
Copy Markdown
Member

@greyli greyli commented Apr 4, 2022

  • Add config SECURITY_SCHEMES and app.security_schemes attribute.
  • Add security parameter to app.doc().

Example:

app = APIFlask(__name__)
app.security_schemes = {
    'ApiKeyAuth': {
      'type': 'apiKey',
      'in': 'header',
      'name': 'X-API-Key',
    }
}

@app.post('/pets')
@app.input(PetInSchema)
@app.output(PetOutSchema, 201)
@app.doc(security='ApiKeyAuth')  # <--
def create_pet(data):
    pet_id = len(pets)
    data['id'] = pet_id
    pets.append(data)
    return pets[pet_id]

This makes it possible to use external auth libraries.

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code docstring.
  • Add an entry in CHANGES.md summarizing the change and linking to the issue and your username.
  • Add *Version changed* or *Version added* note in any relevant docs and docstring.
  • Run pytest and tox, no tests failed.

@greyli greyli changed the title Support customizing security and security schemes Support customizing operation security and security schemes Apr 4, 2022
@greyli greyli added this to the 1.0.0 milestone Apr 5, 2022
- Add config `SECURITY_SCHEMES` and `app.security_schemes` attribute.
- Add `security` parameter to `app.doc()`.
@greyli
Copy link
Copy Markdown
Member Author

greyli commented Apr 5, 2022

The doc and example application will be added later.

@greyli greyli merged commit d1013de into main Apr 5, 2022
@greyli greyli deleted the auth-lib branch April 5, 2022 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support using external authentication library

1 participant