2525 "/auth/login" ,
2626 "/auth/register" ,
2727 "/health" ,
28- "/test-middleware-public"
28+ "/test-middleware-public" ,
29+ "/email/send-test-email" ,
2930]
3031
32+
3133@asynccontextmanager
3234async def lifespan (_ : FastAPI ):
3335 log .info ("Starting up..." )
@@ -49,10 +51,7 @@ async def lifespan(_: FastAPI):
4951 allow_headers = ["*" ],
5052)
5153
52- app .add_middleware (
53- AuthMiddleware ,
54- public_paths = PUBLIC_PATHS
55- )
54+ app .add_middleware (AuthMiddleware , public_paths = PUBLIC_PATHS )
5655
5756app .include_router (auth .router )
5857app .include_router (user .router )
@@ -74,9 +73,9 @@ async def test_middleware(request: Request) -> Dict[str, Any]:
7473 """
7574 Test endpoint that requires authentication and shows middleware-added state.
7675 This will only work if you provide a valid Firebase token in the Authorization header.
77-
76+
7877 Example: Authorization: Bearer your-firebase-token
79-
78+
8079 The response will show all user information added by the Firebase auth middleware.
8180 """
8281 # Get all the attributes from request.state
@@ -95,7 +94,7 @@ async def test_middleware(request: Request) -> Dict[str, Any]:
9594 "user_claims" : getattr (request .state , "user_claims" , None ),
9695 "user_info" : getattr (request .state , "user_info" , None ),
9796 "request_id" : getattr (request .state , "request_id" , None ),
98- "authorization_header" : request .headers .get ("Authorization" , "Not provided" )
97+ "authorization_header" : request .headers .get ("Authorization" , "Not provided" ),
9998 }
10099
101100
@@ -132,74 +131,74 @@ async def test_middleware_public(request: Request) -> Dict[str, Any]:
132131from .middleware .auth import has_roles
133132from .schemas .user import UserRole
134133
134+
135135@app .get ("/test-role-admin" )
136136async def test_role_admin (
137- request : Request ,
138- authorized : bool = has_roles ([UserRole .ADMIN ])
137+ request : Request , authorized : bool = has_roles ([UserRole .ADMIN ])
139138) -> Dict [str , Any ]:
140139 """
141140 Test endpoint that requires the Admin role.
142-
141+
143142 This demonstrates role-based access control using the has_roles dependency.
144143 Only users with the Admin role can access this endpoint.
145144 """
146145 return {
147146 "message" : "You have successfully accessed an admin-only endpoint" ,
148147 "user_id" : request .state .user_id ,
149148 "user_email" : request .state .user_email ,
150- "role" : "admin"
149+ "role" : "admin" ,
151150 }
152151
152+
153153@app .get ("/test-role-volunteer" )
154154async def test_role_volunteer (
155- request : Request ,
156- authorized : bool = has_roles ([UserRole .VOLUNTEER ])
155+ request : Request , authorized : bool = has_roles ([UserRole .VOLUNTEER ])
157156) -> Dict [str , Any ]:
158157 """
159158 Test endpoint that requires the Volunteer role.
160-
159+
161160 This demonstrates role-based access control using the has_roles dependency.
162161 Only users with the Volunteer role can access this endpoint.
163162 """
164163 return {
165164 "message" : "You have successfully accessed a volunteer-only endpoint" ,
166165 "user_id" : request .state .user_id ,
167166 "user_email" : request .state .user_email ,
168- "role" : "volunteer"
167+ "role" : "volunteer" ,
169168 }
170169
170+
171171@app .get ("/test-role-participant" )
172172async def test_role_participant (
173- request : Request ,
174- authorized : bool = has_roles ([UserRole .PARTICIPANT ])
173+ request : Request , authorized : bool = has_roles ([UserRole .PARTICIPANT ])
175174) -> Dict [str , Any ]:
176175 """
177176 Test endpoint that requires the Participant role.
178-
177+
179178 This demonstrates role-based access control using the has_roles dependency.
180179 Only users with the Participant role can access this endpoint.
181180 """
182181 return {
183182 "message" : "You have successfully accessed a participant-only endpoint" ,
184183 "user_id" : request .state .user_id ,
185184 "user_email" : request .state .user_email ,
186- "role" : "participant"
185+ "role" : "participant" ,
187186 }
188187
188+
189189@app .get ("/test-role-multiple" )
190190async def test_role_multiple (
191- request : Request ,
192- authorized : bool = has_roles ([UserRole .ADMIN , UserRole .VOLUNTEER ])
191+ request : Request , authorized : bool = has_roles ([UserRole .ADMIN , UserRole .VOLUNTEER ])
193192) -> Dict [str , Any ]:
194193 """
195194 Test endpoint that requires either Admin OR Volunteer role.
196-
195+
197196 This demonstrates role-based access control with multiple allowed roles.
198197 Users with either Admin or Volunteer roles can access this endpoint.
199198 """
200199 return {
201200 "message" : "You have successfully accessed an endpoint requiring admin OR volunteer role" ,
202201 "user_id" : request .state .user_id ,
203202 "user_email" : request .state .user_email ,
204- "roles_allowed" : ["admin" , "volunteer" ]
203+ "roles_allowed" : ["admin" , "volunteer" ],
205204 }
0 commit comments