forked from nueko/phalcon-oauth2-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.php
46 lines (41 loc) · 1.44 KB
/
app.php
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
35
36
37
38
39
40
41
42
43
44
45
46
<?php
$app->get("/access_token", function () use ($app) {
try {
$response = $app->oauth->authorize->issueAccessToken();
$app->oauth->setData($response);
} catch (\Exception $e) {
$app->oauth->catcher($e);
}
});
$app->get('/authorize', function () use ($app) {
/** @var \League\OAuth2\Server\Grant\AuthCodeGrant $codeGrant */
$authParams = null;
try {
$codeGrant = $app->oauth->authorize->getGrantType('authorization_code');
$authParams = $codeGrant->checkAuthorizeParams();
} catch (\Exception $e) {
return $app->oauth->catcher($e);
}
if ($authParams) {
// Normally at this point you would show the user a sign-in screen and ask them to authorize the requested scopes
// Create a new authorize request which will respond with a redirect URI that the user will be redirected to
//echo($redirectUri);
//$app->response->redirect($redirectUri,true)->sendHeaders();
$redirectUri = $codeGrant->newAuthorizeRequest('client', "testclient", $authParams);
return $redirectUri;
}
});
$app->after(function () use ($app) {
$returned = $app->getReturnedValue();
$app->response->sendHeaders();
if ($returned) {
if(is_scalar($returned))
echo $returned;
else
$app->oauth->setData($returned);
}
$app->response->send();
});
$app->finish(function () use ($app) {
$app->oauth->cleanData();
});