How to use guardpost - 10 common examples

To help you get started, we’ve selected a few guardpost examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RobertoPrevato / BlackSheep / tests / test_normalization.py View on Github external
    Identity,
    User,
    Optional[User],
    Optional[Identity]
])
def test_identity_binder_by_param_type(annotation_type):
    async def handler(param):
        ...

    handler.__annotations__['param'] = annotation_type

    binders = get_binders(Route(b'/', handler), {})

    assert isinstance(binders[0], IdentityBinder)
github RobertoPrevato / BlackSheep / tests / test_auth.py View on Github external
def __init__(self, identity=None):
        if identity is None:
            identity = Identity({
                'id': '001',
                'name': 'Charlie Brown'
            }, 'JWT')
        self.identity = identity
github RobertoPrevato / BlackSheep / tests / test_auth.py View on Github external
async def test_authorization_policy_success():
    app = FakeApplication()

    admin = Identity({
        'id': '001',
        'name': 'Charlie Brown',
        'role': 'admin'
    }, 'JWT')

    app.use_authentication()\
        .add(MockAuthHandler(admin))

    app.use_authorization()\
        .add(AdminsPolicy())

    @auth('admin')
    @app.router.get(b'/')
    async def home():
        return None
github RobertoPrevato / BlackSheep / tests / test_auth.py View on Github external
async def authenticate(self, context: Any) -> Optional[Identity]:
        context.identity = Identity({
            'id': '007',
        })  # NB: an identity without authentication scheme is treated as anonymous identity
        return context.identity
github RobertoPrevato / BlackSheep / tests / test_auth.py View on Github external
    async def authenticate(self, context: Any) -> Optional[Identity]:
        context.identity = Identity({
            'id': '007',
        })  # NB: an identity without authentication scheme is treated as anonymous identity
        return context.identity
github RobertoPrevato / BlackSheep / tests / test_controllers.py View on Github external
async def on_request(self, request: Request):
            request.identity = User({'id': '001', 'name': 'Charlie Brown'}, 'JWTBearer')
github RobertoPrevato / BlackSheep / tests / test_normalization.py View on Github external
    User,
    Optional[User],
    Optional[Identity]
])
def test_identity_binder_by_param_type(annotation_type):
    async def handler(param):
        ...

    handler.__annotations__['param'] = annotation_type

    binders = get_binders(Route(b'/', handler), {})

    assert isinstance(binders[0], IdentityBinder)
github RobertoPrevato / BlackSheep / tests / test_controllers.py View on Github external
async def index(self, request: Request, user: Optional[User]):
            assert hasattr(request, 'identity')
            assert isinstance(request.identity, User)
            return text(request.identity.name)
github RobertoPrevato / BlackSheep / blacksheep / server / bindings.py View on Github external
def __init__(self):
        super().__init__('identity', Identity)
github RobertoPrevato / BlackSheep / blacksheep / server / normalization.py View on Github external
if name in services:
        return FromServices(name, services)

    # 2B. do services contain a service with matching type?
    if annotation in services:
        return FromServices(annotation, services)

    # 3. does route contain a parameter with matching name?
    if route and name in route.param_names:
        return FromRoute(annotation, name)

    # 4. is simple type?
    if annotation in _simple_types_handled_with_query:
        return FromQuery(annotation, name, required=not is_optional)

    if annotation is User or annotation is Identity:
        return IdentityBinder()

    # 5. from json body (last default)
    return FromJson(annotation, required=not is_optional)