Skip to content

Commit

Permalink
fix getting scope from request
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya darchaman committed Nov 2, 2019
1 parent e3f2b80 commit 8e86302
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Http/Controllers/MobilePassportAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ public function store(Request $request)
// get scope
if ($request->has('scope')) {
$scopes = json_decode($request->get('scope'));
if (is_null($scopes)) {
$scopes = $request->get('scope');
}
} else {
$response->setStatus(false);
$response->setMessage($this->getTrans(__FUNCTION__, 'scope_filed_failed'));
Expand All @@ -220,7 +223,7 @@ public function store(Request $request)

// get query in roles
$roles = new AliveMobilePassportRole();
$roles = $roles->whereIn('title', $scopes)->get();
$roles = $roles->whereIn('title', array($scopes))->get();

// check it to exist
if (count($roles->toArray()) == 0) {
Expand Down Expand Up @@ -398,8 +401,11 @@ public function confirmOtp(Request $request)
$scopeKey = $this->otpKeyMaker($request, 'scope');
$jsonEncodedScope = Cache::get($scopeKey);
$scopes = json_decode($jsonEncodedScope, true);
if (is_null($scopes)) {
$scopes = $jsonEncodedScope;
}
$roles = new AliveMobilePassportRole();
$roles = $roles->whereIn('title', $scopes)->first();
$roles = $roles->whereIn('title', array($scopes))->first();

foreach ($roles as $role) {
// assign role to user
Expand Down Expand Up @@ -538,7 +544,10 @@ public function registerByPassword(Request $request)
public function IssueToken(Request $request): JsonResponse
{
$scopes = json_decode($request->get("scope"), true);
$this->token = $this->user->createToken("Personal OTP Token", $scopes);
if (is_null($scopes)) {
$scopes = $request->get("scope");
}
$this->token = $this->user->createToken("Personal OTP Token", array($scopes));
// response object
$response = new ResponseModel();

Expand Down Expand Up @@ -621,4 +630,4 @@ public function createThirdPartyUserToken(CreateThirdPartyUserToken $request): J

return $response;
}
}
}

0 comments on commit 8e86302

Please sign in to comment.