Skip to content

Commit

Permalink
Merge 04f6e77 into 37f4a77
Browse files Browse the repository at this point in the history
  • Loading branch information
chadicus committed Sep 21, 2015
2 parents 37f4a77 + 04f6e77 commit 83ff4da
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Authorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ class Authorize

private $slim;
private $server;
private $template;

public function __construct(Slim $slim, OAuth2\Server $server)
public function __construct(Slim $slim, OAuth2\Server $server, $template = null)
{
$this->slim = $slim;
$this->server = $server;
$this->template = $template ?: self::getDefaultTemplate();
}

public function __invoke()
Expand All @@ -31,7 +33,7 @@ public function __invoke()

$authorized = $this->slim->request()->params('authorized');
if (empty($authorized)) {
//@TODO send to authorize landing page
$this->render($this->template, ['client_id' => $request->query('client_id', false)]);
return;
}

Expand All @@ -53,4 +55,14 @@ public static function register(Slim $slim, OAuth2\Server $server)
{
$slim->map(self::ROUTE, new self($slim, $server))->via('GET', 'POST')->name('authorize');
}

/**
* Helper method to return the default template for the /authorize route
*
* @return string The path to the default template
*/
private static function getDefaultTemplate()
{
return __DIR__ . '/../templates/authorize.phtml';
}
}
46 changes: 46 additions & 0 deletions src/ReceiveCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Chadicus\Slim\OAuth2\Routes;

use Slim\Slim;

class ReceiveCode
{
const ROUTE = '/receive-code';

private $slim;
private $template;

public function __construct(Slim $slim, $template = null)
{
$this->slim = $slim;
$this->template = $template ?: self::getDefaultTemplate();
}

public function __invoke()
{
$this->slim->render($this->template, ['code' => $this->slim->request()->params('code')]);
}

/**
* Register this route with the given Slim application and OAuth2 server
*
* @param Slim $slim The slim framework application instance.
*
* @return void
*/
public static function register(Slim $slim)
{
$slim->map(self::ROUTE, new self($slim))->via('GET', 'POST')->name('receive-code');
}

/**
* Helper method to return the default template for the /authorize route
*
* @return string The path to the default template
*/
private static function getDefaultTemplate()
{
return __DIR__ . '/../templates/receive-code.phtml';
}
}
5 changes: 5 additions & 0 deletions templates/authorize.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<form method="post">
<label>Do You Authorize <?php echo htmlentities($this->data['client_id']); ?>?</label><br />
<input type="submit" name="authorized" value="yes">
<input type="submit" name="authorized" value="no">
</form>
1 change: 1 addition & 0 deletions templates/receive-code.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h2>The authorization code is <?php echo $this->data['code']; ?></h2>

0 comments on commit 83ff4da

Please sign in to comment.