Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting password protected sharing link with expiry date #16

Closed
demin13 opened this issue Nov 2, 2021 · 11 comments
Closed

Getting password protected sharing link with expiry date #16

demin13 opened this issue Nov 2, 2021 · 11 comments
Assignees
Labels
enhancement New feature or request

Comments

@demin13
Copy link

demin13 commented Nov 2, 2021

Hi @dariobauer and @Shub77
I tried to implement an addition feature for getting a password protected sharing link of DriveItem but the post request I had created with the help of this link is not able to get the item using its item_id as it is returning fileNotFound in its response_data.

here is my code, please improve it or add the feature mentioned above.

` @token_required
def get_sharinglink(self, item_id: str):

    request_url = self._API_URL + "me/drive/items/{}/createLink".format(item_id)
    body = {
        "type": "view",
        "password": "1234",
        "scope": "organization"
        }
    response = httpx.post(request_url, headers=self._headers, json=body)

    response_data = response.json()

    return response_data`

Thanks

@dariobauer
Copy link
Owner

Sharing link functionality differs between personal OneDrive and organisation OneDrive (work/school accounts).

It seems that you are wanting to create a password protected link for an organisation which is not possible:

The password of the sharing link that is set by the creator. Optional and OneDrive Personal only.

For personal accounts you can use:

{
  "type": "view",
  "password": "1234",
  "scope": "anonymous"
}

For organisation accounts the process would be to first create a sharing link, and then grant permissions to specific users.

I will look at this in more detail and carry out some testing.

@demin13
Copy link
Author

demin13 commented Nov 3, 2021

Okay , then could you please add one functionality which generates sharing link for the organisation onedrive which should have edit or view option.

Thanks

@dariobauer dariobauer added the enhancement New feature or request label Nov 3, 2021
@dariobauer
Copy link
Owner

I have drafted this feature, refer to the branch sharing-links.

You can test and use this development build by installing the branch directly:

pip install https://github.com/dariobauer/graph-onedrive/archive/sharing-links.zip

Please let me know if you experience any issues.
This will be included in the next feature release.

@dariobauer
Copy link
Owner

This has been merged into main and will be in the next release.

You can use the development version before then if you are so inclined: pip install https://github.com/dariobauer/graph-onedrive/archive/main.zip.

@demin13
Copy link
Author

demin13 commented Nov 7, 2021

Hi @dariobauer
As I tried to get the sharing link by using this code
my_drive.create_share_link(item_id="01H56XG2DAWFPVXRN6T5FYXDJRVYZ2WRBA"
but it raises an exception
raise Exception( Exception: API Error : share link could not be created (Item not found)

I have already given all the permissions in my azure AD as per the permissions given here

I am testing this from a work account.
Also I am not able to make request for permissions
but for DriveItem everything works fine .

please let me know whether I am getting item not found error by doing some mistakes in calling the API or I am missing something in Microsoft Azure App.

Thanks

@dariobauer dariobauer reopened this Nov 7, 2021
@dariobauer
Copy link
Owner

dariobauer commented Nov 7, 2021

As I tried to get the sharing link by using this code
my_drive.create_share_link(item_id="01H56XG2DAWFPVXRN6T5FYXDJRVYZ2WRBA"
but it raises an exception
raise Exception( Exception: API Error : share link could not be created (Item not found)

This error can occur due to several reasons.

Most likely your work is blocking "anonymous" links, unfortunately the Graph API returns "item not found" in this instance, so this is noted in the docs. You can check this by going to the website and manually creating a sharing link, there you will see "Anyone with the link" has been disabled by your organisation.

Screenshot of organisation link settings from the website

Try specifying the scope:

my_drive.create_share_link(item_id="01H56XG2DAWFPVXRN6T5FYXDJRVYZ2WRBA", scope="organization")

Also I am not able to make request for permissions

I have not yet added permissions methods as there are several so will take some time to add.

@demin13
Copy link
Author

demin13 commented Nov 8, 2021

Yeah Thanks , its perfectly working for personal Accounts.

but I am still getting FileNotFound for Work Account as I provided scope: "organization".

@dariobauer
Copy link
Owner

Can you please confirm:

  1. Using the website you can create a shared link for this file?
  2. On the website link settings the blue "people in organization with the link" is available?
  3. Does my_drive.detail_item("01H56XG2DAWFPVXRN6T5FYXDJRVYZ2WRBA") return a valid item? Could you share this response (removing any sensitive data)?

@demin13
Copy link
Author

demin13 commented Nov 8, 2021

yeah sure

  1. On the website link settings the blue "people in organization with the link" is available?
  • yes its available.
  1. Does my_drive.detail_item("01H56XG2DAWFPVXRN6T5FYXDJRVYZ2WRBA") return a valid item? Could you share this response (removing any sensitive data)?
    yeah its returning the details from the above item id

image

If I am trying to make a post request on graph explorer then there also I am getting 404 response as fileNotFound.
I think if there is any admin consent permissions I am missing or something else.. as I have already provided all the delegated permissions needed for creating sharing link.

@dariobauer
Copy link
Owner

dariobauer commented Nov 8, 2021

I cannot reproduce this issue (sharing a file 1.docx in the root of a business OneDrive which blocks anonymous links works fine for me).

Can you please try the following steps:

  1. Go to Graph Explorer and sign in using the business account.
  2. Create a query GET v1.0 https://graph.microsoft.com/v1.0/me/drive/items/{itemid} to verify that you can access the file.
  3. Create a new query POST v1.0 https://graph.microsoft.com/v1.0/me/drive/items/{itemid}/createLink with the body {"type": "view", "scope": "organization"}
  4. You should get a 201 response. If you get a 200 response then the file was previously shared and I would suggest you either remove the sharing on the website or share a different file to test properly.

If you get a 400 series error then it is not an issue with the any of the Python packages.

@demin13
Copy link
Author

demin13 commented Nov 9, 2021

I cannot reproduce this issue (sharing a file 1.docx in the root of a business OneDrive which blocks anonymous links works fine for me).

Can you please try the following steps:

  1. Go to Graph Explorer and sign in using the business account.
  2. Create a new query POST v1.0 https://graph.microsoft.com/v1.0/me/drive/items/{itemid}/createLink with the body {"type": "view", "scope": "organization"}
  • I am still not able to generate the sharable link by making a post request from graph explorer for my organization. I don't know why but I am trying to find the issue as Everything working fine for personal accounts.

If you get a 400 series error then it is not an issue with the any of the Python packages.

Yeah Its not the issue of python packages.
btw thanks a lot for the quick responses.

@demin13 demin13 closed this as completed Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants