@@ -112,30 +112,37 @@ authentic, status_code, message = authenticator.is_authentic()
112112app_uuid = authenticator.get_app_uuid()
113113```
114114
115- #### Flask applications
115+ #### WSGI Applications
116116
117- You will need to create an application instance and initialize it with ` FlaskAuthenticator ` .
118- To specify routes that need to be authenticated use the ` requires_authentication ` decorator.
117+ To apply to a WSGI application you should use the ` MAuthWSGIMiddleware ` . You
118+ can make certain paths exempt from authentication by passing the ` exempt `
119+ option with a set of paths to exempt.
120+
121+ Here is an example for Flask. Note that requesting app's UUID and the
122+ protocol version will be added to the request environment for successfully
123+ authenticated requests.
119124
120125``` python
121- from flask import Flask
122- from mauth_client.flask_authenticator import FlaskAuthenticator, requires_authentication
126+ from flask import Flask, request, jsonify
127+ from mauth_client.consts import ENV_APP_UUID , ENV_PROTOCOL_VERSION
128+ from mauth_client.middlewares import MAuthWSGIMiddleware
123129
124- app = Flask(" Some Sample App" )
125- authenticator = FlaskAuthenticator()
126- authenticator.init_app(app)
130+ app = Flask(" MyApp" )
131+ app.wsgi_app = MAuthWSGIMiddleware(app.wsgi_app, exempt = {" /app_status" })
127132
128- @app.route (" /some/private/route" , methods = [" GET" ])
129- @requires_authentication
130- def private_route ():
131- return " Wibble"
133+ @app.get (" /" )
134+ def root ():
135+ return jsonify({
136+ " msg" : " authenticated" ,
137+ " app_uuid" : request.environ[ENV_APP_UUID ],
138+ " protocol_version" : request.environ[ENV_PROTOCOL_VERSION ],
139+ })
132140
133- @app.route (" /app_status" , methods = [" GET" ])
134- def app_status ():
135- return " OK"
141+ @app.get (" /app_status" )
142+ return " this route is exempt from authentication"
136143```
137144
138- #### ASGI applications
145+ #### ASGI Applications
139146
140147To apply to an ASGI application you should use the ` MAuthASGIMiddleware ` . You
141148can make certain paths exempt from authentication by passing the ` exempt `
0 commit comments