How to restrict application permission to one accounts only

Jack Grub 21 Reputation points
2022-05-06T08:43:06.533+00:00

Hi,

I created an App registration at https://portal.azure.com/, then added certificate client credentials.

added api permittions:

199459-image.png

I'm able to get all user profiles and drives via Python application using Graph URI:

https://graph.microsoft.com/v1.0/users/
https://graph.microsoft.com/v1.0/user/<user_id>/drives/

But I need to restrict access to onedrive - get files of the specific user only.

Please help
Thanks in advance.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,647 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,675 questions
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 37,216 Reputation points
    2022-05-09T08:10:35.397+00:00

    Hi @Jack Grub

    Have you created read or write permissions correctly? You should create read or write permissions and then grant your application the Sites.Selected application permission, then your application can access the selected site collections.

    200030-image.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. CarlZhao-MSFT 37,216 Reputation points
    2022-05-06T09:53:02.043+00:00

    Hi @Jack Grub

    Of course, you can restrict which site collections (drives) your application can access, refer to: https://devblogs.microsoft.com/microsoft365dev/controlling-app-access-on-specific-sharepoint-site-collections/.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Jack Grub 21 Reputation points
    2022-05-06T14:56:14.12+00:00

    Added API permission:

    199743-image.png

    Get all sites:

    https://graph.microsoft.com/v1.0/sites/

    Post permission for site:

    https://graph.microsoft.com/v1.0/sites/<site_id>/permissions

    data = {
    "roles": ["write"],
    "grantedToIdentities": [{
    "application": {
    "id": "<app_id>",
    "displayName": "test"
    }
    }]
    }

    Get permission of site:

    https://graph.microsoft.com/v1.0/sites/<site_id>/permissions

    • empty response

    Any idea?


  3. JanardhanaVedham-MSFT 3,536 Reputation points
    2022-05-06T15:18:02.547+00:00

    Hi @Jack Grub ,

    Microsoft Graph exposes application permissions for apps that call Microsoft Graph under their own identity. Application permissions are used by apps that run without a signed-in user present. Hence it is not possible to restrict Microsoft Graph application permission to one specific user account only. Please note that application permisions are full level permisions are granted to you app registred in Azure AD.

    For application permissions, the effective permissions of your app are the full level of privileges implied by the permission. For example, an app that has the Files.Read.All application permission can gets the files from any user's OneDrive files in the organization.

    For delegated permissions, the effective permissions of your app are the least-privileged intersection of the delegated permissions the app has been granted (by consent) and the privileges of the currently signed-in user. Your app can never have more privileges than the signed-in user. For example, an app that has the Files.Read.All delegated permission only can read all files the signed-in user have access to.

    References :

    https://learn.microsoft.com/en-us/graph/auth/auth-concepts#effective-permissions-in-delegated-vs-application-only-permission-scenarios

    Hope this helps.

    If the answer is helpful to you, please click "Accept Answer" and kindly upvote it. If you have additional questions about this answer, please click "Comment".

    0 comments No comments

  4. Jack Grub 21 Reputation points
    2022-05-06T16:51:32.657+00:00

    Is it possible to restrict access to some site's documents?

    199801-image.png

    How I can specify these selected sites?

    0 comments No comments