Locker\Helpers\Helpers::getUserPassFromOAuth PHP Метод

getUserPassFromOAuth() статический публичный Метод

Gets the Client/Lrs username and password from the OAuth authorization string.
static public getUserPassFromOAuth ( String $authorization ) : [String]
$authorization String
Результат [String]
    static function getUserPassFromOAuth($authorization)
    {
        $token = substr($authorization, 7);
        $db = \App::make('db')->getMongoDB();
        $client_id = $db->oauth_access_tokens->find(['access_token' => $token])->getNext()['client_id'];
        $client_secret = $db->oauth_clients->find(['client_id' => $client_id])->getNext()['client_secret'];
        return [$client_id, $client_secret];
    }

Usage Example

 /**
  * Gets the username and password from the authorization string.
  * @return [String] Formed of [Username, Password]
  */
 static function getUserPassFromAuth()
 {
     $authorization = \LockerRequest::header('Authorization');
     if ($authorization !== null && strpos($authorization, 'Basic') === 0) {
         list($username, $password) = Helpers::getUserPassFromBAuth($authorization);
     } else {
         if ($authorization !== null && strpos($authorization, 'Bearer') === 0) {
             list($username, $password) = Helpers::getUserPassFromOAuth($authorization);
         } else {
             throw new Exceptions\Exception('Invalid auth', 400);
         }
     }
     return [$username, $password];
 }