Revision 5888,
746 bytes
checked in by cristiano, 12 years ago
(diff) |
Ticket #2598 - implementação base REST + oauth
|
-
Property svn:executable set to
*
|
Rev | Line | |
---|
[5888] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /** |
---|
| 4 | * @file |
---|
| 5 | * Sample protected resource. |
---|
| 6 | * |
---|
| 7 | * Obviously not production-ready code, just simple and to the point. |
---|
| 8 | * |
---|
| 9 | * In reality, you'd probably use a nifty framework to handle most of the crud for you. |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | require "lib/OAuth2StorageMongo.php"; |
---|
| 13 | |
---|
| 14 | $token = isset($_GET[OAuth2::TOKEN_PARAM_NAME]) ? $_GET[OAuth2::TOKEN_PARAM_NAME] : null; |
---|
| 15 | |
---|
| 16 | try { |
---|
| 17 | $oauth = new OAuth2(new OAuth2StorageMongo()); |
---|
| 18 | $token = $oauth->getBearerToken(); |
---|
| 19 | $oauth->verifyAccessToken($token); |
---|
| 20 | } catch (OAuth2ServerException $oauthError) { |
---|
| 21 | $oauthError->sendHttpResponse(); |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | // With a particular scope, you'd do: |
---|
| 25 | // $oauth->verifyAccessToken("scope_name"); |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | ?> |
---|
| 29 | |
---|
| 30 | <html> |
---|
| 31 | <head> |
---|
| 32 | <title>Hello!</title> |
---|
| 33 | </head> |
---|
| 34 | <body> |
---|
| 35 | <p>This is a secret.</p> |
---|
| 36 | </body> |
---|
| 37 | </html> |
---|
Note: See
TracBrowser
for help on using the repository browser.