Define Widget Authentication Levels
mainFastApps provides three primary decorators to control how widgets handle authentication and authorization:
- Protected Widgets: Use
@auth_required(scopes=[...]). These require a valid authentication token and specific OAuth2 scopes. If a user is not authenticated, the tool will prompt for login. - Public Widgets: Use
@no_auth. These require no authentication and are accessible to everyone immediately. - Flexible Widgets: Use
@optional_auth(scopes=[...]). These allow for 'freemium' logic where the widget behaves differently depending on whether the user is authenticated or anonymous.
Example usage of decorators:
@auth_required(scopes=["user", "read:data"])
# ... widget logic
@no_auth
# ... widget logic
@optional_auth(scopes=["user"])
# ... widget logic