Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aiohttp-basicauth

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aiohttp-basicauth

HTTP basic authentication middleware for aiohttp 3.0+

  • 1.1.0
  • PyPI
  • Socket score

Maintainers
1

aiohttp-basicauth

CI Coverage Status PyPI version

HTTP basic authentication middleware for aiohttp 3.0+. Inspired by Flask-BasicAuth.

Requirements

  • Python >= 3.7
  • aiohttp >= 3.0

Installation

pip install aiohttp_basicauth

Simple usage

from aiohttp import web
from aiohttp_basicauth import BasicAuthMiddleware


auth = BasicAuthMiddleware(username='user', password='password')
app = web.Application(middlewares=[auth])

web.run_app(app, host='127.0.0.1', port=80)

Protect specific view(s)

from aiohttp import web
from aiohttp_basicauth import BasicAuthMiddleware

auth = BasicAuthMiddleware(username='user', password='password', force=False)


async def public_view(request):
    return web.Response(text='Public view')


@auth.required
async def secret_view(request):
    return web.Response(text='Secret view')


app = web.Application(middlewares=[auth])

app.router.add_route('GET', '/public', public_view)
app.router.add_route('GET', '/secret', secret_view)

web.run_app(app, host='127.0.0.1', port=80)

Advanced usage

You can override check_credentials method to implement more complex user verification logic:

from aiohttp import web
from aiohttp_basicauth import BasicAuthMiddleware


class CustomBasicAuth(BasicAuthMiddleware):
    async def check_credentials(self, username, password, request):
        # here, for example, you can search user in the database by passed `username` and `password`, etc.
        return username == 'user' and password == 'password'


auth = CustomBasicAuth()
app = web.Application(middlewares=[auth])

web.run_app(app, host='127.0.0.1', port=80)

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc