phpSPO icon indicating copy to clipboard operation
phpSPO copied to clipboard

Keep user logged in when viewing PDF file from SharePoint.

Open fabio-carvalho88 opened this issue 3 years ago • 0 comments

Hi there.

I'm using your library with my WordPress website. The main goal is to allow future users to be able to access files stored in specific folders in my SharePoint.

This functionality is already done but I have a problem. Everytime a user clicks in a link to view a PDF file, if he hasn't logged in to the SharePoint, a new window will appear with a form asking him to enter his credentials.

At this moment, users won't have direct access to the SharePoint repository. The only way for them to view files will be trough their Profile - Documentation Area.

The code:

`$username = '@gmail.com'; $password = '**'; $endpoint = "****************";

$authCtx = new AuthenticationContext($endpoint); $authCtx->acquireTokenForUser($username, $password); $ctx = new ClientContext($endpoint, $authCtx);

$files = $ctx->getWeb()->getFolderByServerRelativeUrl("..........")->getFiles(); $ctx->load($files); $ctx->executeQuery();

foreach ($files->getData() as $file) { try { $file_name = $file->getName(); echo 'link with href to access files in a specific folder adding $file_name in the end of the url'

        } catch (Exception $e) {
            print "File download failed:\r\n";
        }
    }        

}`

Can you help me understand how to make it possible for a user to view the PDF files in the browser without having to log in on my sharepoint portal? I want them to use the credentials I'm passing in $authCtx and keep them logged in with them.

fabio-carvalho88 avatar Apr 01 '21 09:04 fabio-carvalho88