예제 #1
0
async def test_identity_binder():
    request = Request("GET", b"/", None)
    request.identity = Identity({})

    parameter = IdentityBinder(Identity)

    value = await parameter.get_value(request)

    assert value is request.identity
예제 #2
0
async def test_identity_binder():
    request = Request('GET', b'/', None)
    request.identity = object()

    parameter = IdentityBinder()

    value = await parameter.get_value(request)

    assert value is request.identity
예제 #3
0
    async def authenticate(self, context: Request) -> Optional[Identity]:
        # TODO: implement desired logic;
        #       for example, a user context can be created using Request's cookies; or an Authorization header
        # Here, in this example, a user is hardcoded to provide an example.
        #
        # Request handlers are injected with this user, when a parameter is named 'user' without type annotations,
        # or when type annotation is guardpost.User or guardpost.Identity

        user = User(
            {
                'id': '2c853c84-4abf-4cc1-901a-83a32431495b',
                'name': 'Cesar Costa'
            }, 'DEMO')

        # NB: do not change the name `identity` property.
        # It is called `identity` because it can be either a human (user) or a machine (service)
        context.identity = user
        return user
예제 #4
0
 async def on_request(self, request: Request):
     request.identity = User({'id': '001', 'name': 'Charlie Brown'}, 'JWTBearer')
예제 #5
0
 async def on_request(self, request: Request):
     request.identity = User({
         "id": "001",
         "name": "Charlie Brown"
     }, "JWTBearer")