Skip to content

Commit

Permalink
SS4 fixes (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinglozzer authored and colymba committed Feb 21, 2019
1 parent b24b7eb commit 103e1c6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/Authenticators/TokenAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\IdentityStore;
use SilverStripe\Security\Member;
use SilverStripe\Security\MemberAuthenticator\LostPasswordHandler;
use SilverStripe\Security\MemberAuthenticator\MemberAuthenticator;
Expand Down Expand Up @@ -422,10 +423,12 @@ private function validateAPIToken($token, $request)
}
//all good, log Member in
if (is_a($tokenOwner, Member::class)) {
# $tokenOwner->logIn();
# this is a login without the logging
Config::inst()->set(Member::class, 'session_regenerate_id', true);
$request->getSession()->set("loggedInAs", $tokenOwner->ID);
Config::nest();
Config::modify()->set(Member::class, 'session_regenerate_id', true);
$identityStore = Injector::inst()->get(IdentityStore::class);
$identityStore->logIn($tokenOwner, false, $request);
Config::unnest();
}

return true;
Expand Down
23 changes: 17 additions & 6 deletions src/RESTfulAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

namespace Colymba\RESTfulAPI;

use Colymba\RESTfulAPI\RESTfulAPIError;
use Colymba\RESTfulAPI\Authenticators\Authenticator;
use Colymba\RESTfulAPI\PermissionManagers\PermissionManager;
use Colymba\RESTfulAPI\QueryHandlers\QueryHandler;
use Colymba\RESTfulAPI\Serializers\Serializer;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Config\Config;
use SilverStripe\Control\Controller;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Member;

/**
* SilverStripe 3 RESTful API
*
Expand Down Expand Up @@ -232,7 +238,8 @@ public function init()
* get response from API Authenticator
* then passes it on to $answer()
*
* @param HTTPRequest $request HTTP request
* @param HTTPRequest $request HTTP request
* @return HTTPResponse
*/
public function auth(HTTPRequest $request)
{
Expand Down Expand Up @@ -269,7 +276,8 @@ public function auth(HTTPRequest $request)
* get response from API PermissionManager
* then passes it on to $answer()
*
* @param HTTPRequest $request HTTP request
* @param HTTPRequest $request HTTP request
* @return HTTPResponse
*/
public function acl(HTTPRequest $request)
{
Expand Down Expand Up @@ -307,7 +315,7 @@ public function acl(HTTPRequest $request)
*
* @todo move authentication check to another methode
*
* @param SS_HTTPRequest $request HTTP request
* @param HTTPRequest $request HTTP request
* @return string json object of the models found
*/
public function index(HTTPRequest $request)
Expand Down Expand Up @@ -350,8 +358,9 @@ public function index(HTTPRequest $request)
* Output the API response to client
* then exit.
*
* @param string $json Response body
* @param boolean $corsPreflight Set to true if this is a XHR preflight request answer. CORS shoud be enabled.
* @param string $json Response body
* @param boolean $corsPreflight Set to true if this is a XHR preflight request answer. CORS shoud be enabled.
* @return HTTPResponse
*/
public function answer($json = null, $corsPreflight = false)
{
Expand All @@ -378,6 +387,7 @@ public function answer($json = null, $corsPreflight = false)
* then exit.
*
* @param RESTfulAPIError $error Error object to return
* @return HTTPResponse
*/
public function error(RESTfulAPIError $error)
{
Expand All @@ -402,6 +412,7 @@ public function error(RESTfulAPIError $error)
* to an HTTPResponse
*
* @param HTTPResponse $answer The updated response if CORS are neabled
* @return HTTPResponse
*/
private function setAnswerCORS(HTTPResponse $answer)
{
Expand Down

0 comments on commit 103e1c6

Please sign in to comment.