forked from Neoteroi/BlackSheep-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
34 lines (24 loc) · 894 Bytes
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from blacksheep.server.application import Application
from blacksheep.server.authentication.jwt import JWTBearerAuthentication
from blacksheep.server.authorization import auth
from guardpost.common import AuthenticatedRequirement, Policy
app = Application()
app.use_authentication().add(
JWTBearerAuthentication(
authority="https://login.microsoftonline.com/robertoprevatogmail.onmicrosoft.com",
valid_audiences=["104bca60-c5a7-4ab9-83e1-7b9c8dad71e2"],
valid_issuers=[
"https://login.microsoftonline.com/b62b317a-19c2-40c0-8650-2d9672324ac4/v2.0"
],
)
)
authorization = app.use_authorization()
authorization += Policy("any_name", AuthenticatedRequirement())
get = app.router.get
@get("/")
def home():
return "Hello, World"
@auth("any_name")
@get("/api/message")
def example():
return "This is only for authenticated users"