Fix on deleted member
* if user is deleted and the user is already logged , then you get an error * refactored token generation Change-Id: I04d1ad055d05abe4d9228cde58c26250b3674225
This commit is contained in:
parent
faf21175fe
commit
bb69e419ba
|
@ -5,11 +5,11 @@ namespace auth;
|
|||
use Eloquent;
|
||||
use Illuminate\Auth\UserInterface;
|
||||
use Member;
|
||||
use MemberPhoto;
|
||||
use oauth2\models\IApiScope;
|
||||
use oauth2\models\IApiScopeGroup;
|
||||
use oauth2\models\IOAuth2User;
|
||||
use openid\model\IOpenIdUser;
|
||||
use utils\exceptions\EntityNotFoundException;
|
||||
use utils\model\BaseModelEloquent;
|
||||
use utils\model\IEntity;
|
||||
|
||||
|
@ -71,7 +71,7 @@ class User extends BaseModelEloquent implements UserInterface, IOpenIdUser, IOAu
|
|||
if (is_null($this->member)) {
|
||||
$this->member = Member::where('ID', '=', $this->external_identifier)->first();
|
||||
}
|
||||
|
||||
if (is_null($this->member)) throw new EntityNotFoundException(sprintf('member id %s',$this->external_identifier));
|
||||
return $this->member;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,29 +14,9 @@
|
|||
|
||||
namespace oauth2\services;
|
||||
|
||||
use oauth2\OAuth2Protocol;
|
||||
use utils\model\Identifier;
|
||||
use utils\services\UniqueIdentifierGenerator;
|
||||
use Zend\Math\Rand;
|
||||
use Auth;
|
||||
|
||||
/**
|
||||
* Class AccessTokenGenerator
|
||||
* @package oauth2\services
|
||||
*/
|
||||
final class AccessTokenGenerator extends UniqueIdentifierGenerator {
|
||||
|
||||
/**
|
||||
* @param Identifier $identifier
|
||||
* @return Identifier
|
||||
*/
|
||||
protected function _generate(Identifier $identifier)
|
||||
{
|
||||
$current_user = Auth::user();
|
||||
$user_id = !is_null($current_user) ? strval($current_user->getId()): '';
|
||||
$now = \DateTime::createFromFormat('U.u', microtime(true));
|
||||
$salt = $now->format("YmdHisu").$user_id;
|
||||
$value = Rand::getString($identifier->getLenght() - ( strlen($salt) + 1), OAuth2Protocol::VsChar, true);
|
||||
return $identifier->setValue($value.'.'.$salt);
|
||||
}
|
||||
final class AccessTokenGenerator extends OAuth2ATokenGenerator {
|
||||
}
|
|
@ -14,29 +14,10 @@
|
|||
|
||||
namespace oauth2\services;
|
||||
|
||||
use oauth2\OAuth2Protocol;
|
||||
use utils\model\Identifier;
|
||||
use utils\services\UniqueIdentifierGenerator;
|
||||
use Zend\Math\Rand;
|
||||
use Auth;
|
||||
|
||||
/**
|
||||
* Class AuthorizationCodeGenerator
|
||||
* @package oauth2\services
|
||||
*/
|
||||
final class AuthorizationCodeGenerator extends UniqueIdentifierGenerator {
|
||||
|
||||
/**
|
||||
* @param Identifier $identifier
|
||||
* @return Identifier
|
||||
*/
|
||||
protected function _generate(Identifier $identifier)
|
||||
{
|
||||
$current_user = Auth::user();
|
||||
$user_id = !is_null($current_user) ? strval($current_user->getId()): '';
|
||||
$now = \DateTime::createFromFormat('U.u', microtime(true));
|
||||
$salt = $now->format("YmdHisu").$user_id;
|
||||
$value = Rand::getString($identifier->getLenght() - ( strlen($salt) + 1), OAuth2Protocol::VsChar, true);
|
||||
return $identifier->setValue($value.'.'.$salt);
|
||||
}
|
||||
final class AuthorizationCodeGenerator extends OAuth2ATokenGenerator {
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright 2016 OpenStack Foundation
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
namespace oauth2\services;
|
||||
|
||||
use oauth2\OAuth2Protocol;
|
||||
use utils\model\Identifier;
|
||||
use utils\services\UniqueIdentifierGenerator;
|
||||
use Zend\Math\Rand;
|
||||
|
||||
/**
|
||||
* Class OAuth2ATokenGenerator
|
||||
* @package libs\oauth2\services
|
||||
*/
|
||||
class OAuth2ATokenGenerator extends UniqueIdentifierGenerator
|
||||
{
|
||||
/**
|
||||
* @param Identifier $identifier
|
||||
* @return Identifier
|
||||
*/
|
||||
protected function _generate(Identifier $identifier)
|
||||
{
|
||||
return $identifier->setValue(Rand::getString($identifier->getLenght(), OAuth2Protocol::VsChar, true));
|
||||
}
|
||||
}
|
|
@ -14,29 +14,9 @@
|
|||
|
||||
namespace oauth2\services;
|
||||
|
||||
use oauth2\OAuth2Protocol;
|
||||
use utils\model\Identifier;
|
||||
use utils\services\UniqueIdentifierGenerator;
|
||||
use Zend\Math\Rand;
|
||||
use Auth;
|
||||
|
||||
/**
|
||||
* Class RefreshTokenGenerator
|
||||
* @package oauth2\services
|
||||
*/
|
||||
final class RefreshTokenGenerator extends UniqueIdentifierGenerator {
|
||||
|
||||
/**
|
||||
* @param Identifier $identifier
|
||||
* @return Identifier
|
||||
*/
|
||||
protected function _generate(Identifier $identifier)
|
||||
{
|
||||
$current_user = Auth::user();
|
||||
$user_id = !is_null($current_user) ? strval($current_user->getId()): '';
|
||||
$now = \DateTime::createFromFormat('U.u', microtime(true));
|
||||
$salt = $now->format("YmdHisu").$user_id;
|
||||
$value = Rand::getString($identifier->getLenght() - ( strlen($salt) + 1), OAuth2Protocol::VsChar, true);
|
||||
return $identifier->setValue($value.'.'.$salt);
|
||||
}
|
||||
final class RefreshTokenGenerator extends OAuth2ATokenGenerator {
|
||||
}
|
|
@ -41,7 +41,9 @@ final class NonceUniqueIdentifierGenerator extends UniqueIdentifierGenerator {
|
|||
protected function _generate(Identifier $identifier){
|
||||
|
||||
$salt = Rand::getString(self::NonceSaltLength, self::NoncePopulation, true);
|
||||
$raw_nonce = gmdate('Y-m-d\TH:i:s\Z') . $salt;
|
||||
$date_part = false;
|
||||
do{ $date_part = gmdate('Y-m-d\TH:i:s\Z'); } while($date_part === false);
|
||||
$raw_nonce = $date_part. $salt;
|
||||
$identifier->setValue($raw_nonce);
|
||||
return $identifier;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue