Last active
August 29, 2015 14:14
-
-
Save linhmtran168/9eb43e7976565d22f6bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Route::get('authorize', array('before' => 'check-authorization-params|auth', function() | |
{ | |
// get the data from the check-authorization-params filter | |
$params = Session::get('authorize-params'); | |
// get the user id | |
$params['user_id'] = Auth::user()->id; | |
// check if user already has authorized client for scopes | |
$scopesAuthorized = Auth::user()->scopesAuthorizedByClientId($params['client_id']); | |
$scopesNotAuthorized = array_diff(array_fetch($params['scopes'], 'scope'), $scopesAuthorized); | |
if(sizeof($scopesNotAuthorized) == 0) | |
{ | |
// all requested scopes have already been approved by the user -> skip the authorization dialog | |
$code = AuthorizationServer::newAuthorizeRequest('user', $params['user_id'], $params); | |
Session::forget('authorize-params'); | |
return Redirect::to(AuthorizationServer::makeRedirectWithCode($code, $params)); | |
} | |
// display the authorization form | |
return View::make('oauth.authorize', array('params' => $params)); | |
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User extends Eloquent implements UserInterface, RemindableInterface { | |
// ... | |
public function scopesAuthorizedByClientId($clientId) | |
{ | |
$scopesAuthorized = array(); | |
$session = DB::table('oauth_sessions') | |
->where('client_id', $clientId) | |
->where('owner_type', 'user') | |
->where('owner_id', $this->id) | |
->first(); | |
if(!$session) | |
{ | |
return $scopesAuthorized; | |
} | |
$accessToken = DB::table('oauth_session_access_tokens') | |
->where('session_id', $session->id) | |
->first(); | |
if(!$accessToken) | |
{ | |
return $scopesAuthorized; | |
} | |
$scopes = DB::table('oauth_session_token_scopes') | |
->where('session_access_token_id', $accessToken->id) | |
->get(); | |
foreach($scopes as $scope) | |
{ | |
$scopeData = DB::table('oauth_scopes') | |
->where('id', $scope->scope_id) | |
->first(); | |
if($scopeData) | |
{ | |
$scopesAuthorized[]= $scopeData->scope; | |
} | |
} | |
return $scopesAuthorized; | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment