krizalys / onedrive-php-sdk

OneDrive SDK for PHP
BSD 3-Clause "New" or "Revised" License
144 stars 66 forks source link

How to obtain a users ID or UserPrincipleName OR How to upload file into 3rd Party Folder #78

Closed tudders closed 4 years ago

tudders commented 4 years ago

Hi there. Is there a way to get the id/UPN for a user in this library so I can push files into 3rd party folders?

There's a method here that points towards it, but I can't see where I can get the ID : getDriveByUser($idOrUserPrincipalName)

A 3rd party authenticates, but how to put stuff in their folders?

Note - client ID is not the $idOrUserPrincipleName. It's the app ID.

tudders commented 4 years ago

Some searching yielded: https://stackoverflow.com/questions/57343882/current-user-for-apps-in-microsoft-onedrive-api

The auth flow doesn't work for '/me' when '/me' is someone else.

(But I think this used to work??)

krizalys commented 4 years ago

@tudders For example, you can access a user ID from the Drive owner property: https://github.com/krizalys/onedrive-php-sdk/blob/2.6.0/test/functional/ClientTest.php#L144

If you are the administrator of an organization, you can use the Graph to list users in the organization and get their IDs.

Apart from this scenario, by design, you will not easily be able to access other user information, for security reasons.

With this library, the recommended way to upload to a 3rd party account is as follows:

  1. You integrate the library to a registed app
  2. Users of your app sign in to their account via the library and give their consent to grant your app permissions to use their account
  3. You app takes over and can upload to their account
  4. Users can revoke permissions to your app