Skip to main content

RLS in Embeeding

we can directly define RLS when creating guesttoken 

public function getGuestToken()
{
    $token = $this->login();

    $response = Http::withHeaders([
        'Content-Type' => 'application/json'
    ])->log()
      ->withToken($token)
      ->post("{$this->baseUrl}/api/v1/security/guest_token", [
        'user' => [
            'username' => '',
            'first_name' => '',
            'last_name' => ''
        ],
        'resources' => [
            [
                'type' => 'dashboard',
                'id' => $this->dashboardId
            ]
        ],
        'rls' => [
              //['clause'=> 'fakultas = "Fakultas Kedokteran"']
              ] ,
    ]);

    if ($response->successful()) {
        return $response->json('token');
    }

    throw new \Exception('Failed to get guest token: ' . $response->body());
}