Use the New-ApplicationAccessPolicy cmdlet to restrict or deny access to a specific set of mailboxes by an application that uses APIs (Outlook REST, Microsoft Graph, or Exchange Web Services (EWS)).
Configure ApplicationAccessPolicy.
To configure an application access policy and limit the scope of application permission
1) Connect to Exchange Online PowerShell. For details, see Connect to Exchange Online PowerShell
2) Identify the app’s client ID and a mail-enabled security group to restrict the app’s access to. Identify the app’s application (client) ID in the Azure app registration portal. Create a new mail-enabled security group or use an existing one and identify the email address for the group.
3) Create an application access policy. Run the following command, replacing the AppId, PolicyScopeGroupId, and Description arguments.
Example:
New-ApplicationAccessPolicy -AccessRight RestrictAccess -AppId "e7e4dbfc-046f-4074-9b3b-2ae8f144f59b" -PolicyScopeGroupId EvenUsers@AppPolicyTest2.com -Description "Restrict this app's access to members of security group EvenUsers."
This example creates a new application access policy with the following settings:
AccessRight: RestrictAccess,
AppIDs: e7e4dbfc-046f-4074-9b3b-2ae8f144f59b,
PolicyScopeGroupId: EvenUsers@AppPolicyTest2.com,
Description: Restrict this app's access to members of security group EvenUsers.
4) Test the newly created application access policy. Run the following command, replacing the AppId and Identity arguments.
Test-ApplicationAccessPolicy -Identity user1@contoso.com -AppId e7e4dbfc-046-4074-9b3b-2ae8f144f59b
The output of this command will indicate whether the app has access to User1’s mailbox
For more details refer these link1 and link2