Last active
February 28, 2016 19:45
-
-
Save andevsoftware/41b6c882d9d06b77992a to your computer and use it in GitHub Desktop.
Phalcon REST - Restrict Access On Resources
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$api->resource(Resource::crud('/users', 'User') | |
// Here we restrict access to all endpoints | |
// on this Resource. The `User` role is not allowed | |
// to access all endpoints by default. | |
->deny(AclRoles::UNAUTHORIZED, AclRoles::USER) | |
// Because access can be overridden, | |
// we specifically allow access for | |
// the `User` role on this endpoint. | |
->endpoint(Endpoint::get('/me', 'me') | |
->allow(AclRoles::USER) | |
// .. more endpoint setup | |
) | |
// When a user has already been authenticated, it doesn't | |
// make sense to let them gain access on this endpoint. | |
->endpoint(Endpoint::post('/authenticate', 'authenticate') | |
->allow(AclRoles::UNAUTHORIZED) | |
->deny(AclRoles::AUTHORIZED) | |
// .. more endpoint setup | |
) | |
// .. more resource setup | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment