Metadata-Version: 2.1
Name: sanic_csrf
Version: 0.1.2
Summary: Protection from CSRF attacks for Sanic framework
Home-page: https://github.com/vlad1777d/sanic_csrf
Author: vlad1777d (Vladislav Naumov)
Author-email: naumovvladislav@mail.ru
License: UNKNOWN
Description: ### sanic_csrf
        
        Works with all modern web-browsers, which support SameSite cookies.
        (Firefox 60, Google Chrome 51, Opera 39 and later)
        
        Checks request for CSRF token.
        If CSRF is absent or invalid:
            If it's a get request - installs new token in cookie and redirects to same page.
            In other cases - raises 403 exception (forbidden).
        
        Requires some session middleware to be installed.
        That session plugin must use such interface:
        	```python
            request['session'].get('variable') or request['session']['variable']
            request['session']['variable'] = 4
            ```
        For example, this ones will fit:
        - 'sanic_session' (https://github.com/subyraman/sanic_session);
        - 'sanic_session' (https://github.com/vlad1777d/sanic_session)
            (fork of previous, more convenient middleware installation,
            can be used without package installation);
        
        
        ## Example
        
        A simple example:
        
        
        ```python
            from sanic import Sanic
            from sanic.response import text
            import sanic_session
            import sanic_csrf
        
        
            app = Sanic()
            sanic_session.install_middleware(app, 'InMemorySessionInterface')
            sanic_csrf.install_middleware(app)
        
        
            @app.route("/")
            async def index(request):
                # interact with the session like a normal dict
                if not request['session'].get('foo'):
                    request['session']['foo'] = 0
        
                request['session']['foo'] += 1
        
                return text(request['session']['foo'])
        
            if __name__ == "__main__":
                app.run(host="0.0.0.0", port=8000, debug=True)
        ```
        
        
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown
