%3CLINGO-SUB%20id%3D%22lingo-sub-2115812%22%20slang%3D%22en-US%22%3EAzure%20AD%3A%20Custom%20Application%20Consent%20Policies%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2115812%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHey%20folks%2C%20Eric%20Woodruff%20here%20%E2%80%93%20a%20Customer%20Engineer%20who%20lives%20in%20the%20world%20of%20Azure%20Active%20Directory.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EToday%20we%20are%20going%20to%20be%20examining%20custom%20app%20consent%20policies%20in%20Azure%20Active%20Directory%2C%20and%20how%20you%20can%20leverage%20them%20for%20some%20advanced%20and%20granular%20consent%20policies%20within%20your%20Azure%20AD%20tenant.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20won%E2%80%99t%20really%20be%20diving%20into%20the%20basics%20of%20application%20consent%20today%2C%20but%20it%E2%80%99s%20increasingly%20becoming%20a%20topic%20of%20discussion%20with%20customers%2C%20to%20ensure%20that%20they%20are%20keeping%20their%20organization%20secure%20and%20that%20they%20have%20insight%20and%20control%20over%20what%20applications%20their%20end%20users%20are%20accessing%20with%20their%20organization%20identities.%20For%20a%20bit%20more%20background%20on%20application%20consent%2C%20as%20well%20as%20why%20you%20should%20be%20aware%20of%20it%20within%20your%20organization%2C%20refer%20to%20some%20of%20our%20docs%20%E2%80%93%20and%20perhaps%20the%20future%20will%20hold%20further%20blog%20posts%20discussing%20such.%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Fmanage-apps%2Fconfigure-user-consent%3Ftabs%3Dazure-portal%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EConfigure%20how%20end-users%20consent%20to%20applications%20using%20Azure%20AD%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fmicrosoft-365%2Fsecurity%2Foffice-365-security%2Fdetect-and-remediate-illicit-consent-grants%3Fview%3Do365-worldwide%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EDetect%20and%20Remediate%20Illicit%20Consent%20Grants%20-%20Office%20365%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1823924056%22%20id%3D%22toc-hId--526996373%22%3EBackground%3C%2FH2%3E%0A%3CP%3EFor%20customers%20that%20want%20to%20restrict%20the%20ability%20for%20end%20users%20to%20grant%20consent%20to%20applications%2C%20the%20trade-off%20between%20security%20and%20usability%20starts%20to%20come%20into%20play.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20have%20multiple%20options%20to%20help%20customers%20try%20and%20find%20this%20balance%20%E2%80%93%20the%20ability%20for%20organizations%20to%20specify%20permissions%20considered%20low%20impact%2C%20or%20from%20verified%20publishers.%20And%20we%20have%20the%20ability%20for%20organizations%20to%20enable%20the%20preview%20feature%20of%20admin%20consent%20workflows%20%E2%80%93%20when%20a%20user%20needs%20an%20app%2C%20a%20request%20will%20be%20sent%20to%20specified%20administrators%20to%20approve%20(or%20deny)%20it.%20And%20for%20most%20of%20our%20customers%20these%20solutions%20fit%20their%20business%20needs.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20have%20a%20subset%20of%20customers%20that%20wish%20to%20restrict%20the%20ability%20for%20end%20users%20to%20be%20able%20to%20onboard%20new%20applications%20into%20the%20organization%20and%20require%20that%20the%20end%20users%20still%20must%20consent%20to%20the%20delegated%20permissions%20before%20being%20able%20to%20use%20the%20application.%20With%20a%20custom%20app%20consent%20policy%2C%20we%20can%20meet%20these%20needs.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--728232905%22%20id%3D%22toc-hId-1960516460%22%3EProblem%20Scenario%3C%2FH2%3E%0A%3CP%3EIn%20our%20demo%20Azure%20AD%20tenant%2C%20we%20want%20to%20allow%20for%20users%20to%20be%20able%20to%20perform%20a%20delegated%20user%20consent%20for%20the%20Fabrikam%20B2C%20Enterprise%20Application%20%E2%80%93%20in%20your%20Azure%20AD%20tenant%20this%20could%20be%20any%20Enterprise%20App%20that%20requires%20user%20consent.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20have%20already%20gone%20through%20the%20process%20of%20onboarding%20the%20application%20into%20Azure%20AD%2C%20but%20we%20still%20want%20to%20require%20the%20users%20to%20accept%20the%20delegated%20permissions%20when%20accessing%20this%20application.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20our%20tenant%2C%20we%20have%20disabled%20the%20ability%20for%20users%20to%20consent%20to%20apps%20accessing%20data%20on%20their%20behalf.%20And%20while%20the%20admin%20consent%20workflow%20would%20allow%20for%20granting%20permissions%2C%20that%20process%20also%20performs%20an%20Admin%20consent%20grant%2C%20so%20subsequently%20users%20would%20be%20able%20to%20access%20the%20application%20without%20needing%20to%20consent%20to%20the%20permissions%20themselves.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Eric_Woodruff_0-1612548756170.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F252755iFE304200C3F536A3%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Eric_Woodruff_0-1612548756170.png%22%20alt%3D%22Eric_Woodruff_0-1612548756170.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3EThe%20app%20consent%20approval%20workflow%20that%20just%20won%E2%80%99t%20fit%20our%20business%20requirements.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1014577430%22%20id%3D%22toc-hId-153061997%22%3EImplementation%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1734093036%22%20id%3D%22toc-hId-843623471%22%3E1%20%7C%20Revoke%20Any%20Existing%20Permissions%3C%2FH3%3E%0A%3CP%3EDepending%20on%20how%20the%20application%20was%20onboarded%2C%20there%20may%20be%20a%20pre-existing%20set%20of%20permissions%20already%20accepted%20that%20we%20may%20want%20to%20remove%3B%20if%20this%20does%20not%20fit%20your%20case%20then%20just%20move%20on%20to%20step%202.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELuckily%2C%20Azure%20AD%20already%20provides%20an%20easy%20means%20of%20giving%20you%20a%20PowerShell%20snippet%20to%20revoke%20existing%20approvals.%20From%20within%20the%20%3CSTRONG%3EEnterprise%20Application%3C%2FSTRONG%3E%2C%20if%20you%20select%20%3CSTRONG%3EPermissions%3C%2FSTRONG%3E%20under%20the%20%3CSTRONG%3ESecurity%3C%2FSTRONG%3E%20section%20of%20the%20applications%20blade%2C%20and%20within%20the%20details%20blade%2C%20select%20%3CSTRONG%3EReview%20permissions%3C%2FSTRONG%3E%20at%20the%20top%2C%20and%20then%20select%20%3CSTRONG%3EThis%20application%20has%20more%20permissions%20than%20I%20want%3C%2FSTRONG%3E.%20There%20will%20be%20a%20PowerShell%20script%20presented%20that%20you%20can%20run%20to%20remove%20all%20pre-existing%20permission%20grants.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-8717299%22%20id%3D%22toc-hId--963830992%22%3E2%20%7C%20Build%20A%20Custom%20Application%20Consent%20Policy%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId-1555014129%22%20id%3D%22toc-hId--273269518%22%3E2.1%20%7C%20Examining%20Existing%20Policies%3C%2FH4%3E%0A%3CP%3ENow%20that%20we%20have%20a%20fresh%20slate%20for%20our%20application%2C%20we%20are%20ready%20to%20build%20a%20custom%20app%20consent%20policy.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EEnsure%20that%20we%20are%20using%20the%20latest%20version%20of%20the%20%3CA%20href%3D%22https%3A%2F%2Fwww.powershellgallery.com%2Fpackages%2FAzureADPreview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EAzure%20AD%20Preview%20PowerShell%20module%3C%2FA%3E%2C%20connect%20to%20your%20Azure%20AD%20tenant.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAfter%20connecting%20to%20Azure%20AD%2C%20we%20can%20get%20familiar%20with%20the%20policies%20that%20already%20exist%20in%20our%20tenant%3B%20all%20customers%20will%20have%20some%20out%20of%20the%20box%20consent%20policies%20within%20their%20tenant%2C%20as%20we%20can%20see%20when%20we%20enumerate%20them%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EGet-AzureADMSPermissionGrantPolicy%20%7C%20ft%20Id%2CDisplayName%2CDescription%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Eric_Woodruff_1-1612548756180.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F252757i3E26FFDF3D89C103%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Eric_Woodruff_1-1612548756180.png%22%20alt%3D%22Eric_Woodruff_1-1612548756180.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId--997142832%22%20id%3D%22toc-hId--2080723981%22%3E%3CBR%20%2F%3E2.2%20%7C%20Create%20New%20Policy%3C%2FH4%3E%0A%3CP%3ENow%20that%20we%20see%20what%20policies%20already%20exist%2C%20we%20can%20create%20our%20new%20policy%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3ENew-AzureADMSPermissionGrantPolicy%20%60%0A%20-Id%20%22fabrikam-b2c-app%22%20%60%0A%20-DisplayName%20%22Fabrikam%20B2C%20App%20Consent%20Policy%22%20%60%0A%20-Description%20%22Custom%20consent%20policy%20for%20Fabrikam%20B2C%20App.%22%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Eric_Woodruff_2-1612548756186.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F252756i12ADF24A752DD569%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Eric_Woodruff_2-1612548756186.png%22%20alt%3D%22Eric_Woodruff_2-1612548756186.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAfter%20creation%2C%20we%20can%20enumerate%20our%20policies%20again%20and%20verify%20creation%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Eric_Woodruff_3-1612548756194.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F252758iCC3AD6983CFFD368%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Eric_Woodruff_3-1612548756194.png%22%20alt%3D%22Eric_Woodruff_3-1612548756194.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId-745667503%22%20id%3D%22toc-hId-406788852%22%3E2.3%20%7C%20Create%20Policy%20Conditions%3C%2FH4%3E%0A%3CP%3ENow%20that%20we%20have%20the%20policy%2C%20we%20must%20create%20the%20policy%20conditions%20that%20will%20be%20defined%20within%20it.%20When%20defining%20our%20policy%2C%20we%20have%20several%20conditions%20we%20can%20use%20to%20create%20include%20and%2For%20exclude%20conditions.%20I%20won%E2%80%99t%20be%20diving%20into%20all%20those%20conditions%20here%2C%20but%20they%20are%20notated%20in%20our%20documentation%3A%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Fmanage-apps%2Fmanage-app-consent-policies%23supported-conditions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EManage%20app%20consent%20policies%20in%20Azure%20AD%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20our%20case%2C%20we%20are%20going%20to%20build%20a%20policy%20that%20is%20specific%20to%20the%3CSTRONG%3E%20ClientApplicationIds%3C%2FSTRONG%3E%20condition%2C%20which%20will%20contain%20the%20Application%20ID%20that%20is%20assigned%20to%20the%20Fabrikam%20B2C%20Application%20in%20our%20tenant%20%E2%80%93%20the%20Application%20ID%20will%20be%20unique%20for%20each%20application%20in%20a%20tenant.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3ENew-AzureADMSPermissionGrantConditionSet%20%60%0A%20-PolicyId%20%22fabrikam-b2c-app%22%20%60%0A%20-ConditionSetType%20%22includes%22%20%60%0A%20-PermissionType%20%22delegated%22%20%60%0A%20-ClientApplicationIds%20%22%3CAPPLICATION-ID%3E%22%0A%3C%2FAPPLICATION-ID%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Eric_Woodruff_4-1612548756201.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F252759i3762B821F9050505%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Eric_Woodruff_4-1612548756201.png%22%20alt%3D%22Eric_Woodruff_4-1612548756201.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1609975953%22%20id%3D%22toc-hId-396285748%22%3E%3CFONT%20color%3D%22%23000000%22%3E3%20%7C%20Create%20a%20Custom%20Azure%20AD%20Role%3C%2FFONT%3E%3C%2FH3%3E%0A%3CP%3ENow%20that%20we%20have%20our%20policy%20defined%2C%20we%20need%20to%20create%20a%20custom%20role%20within%20Azure%20AD%20to%20assign%20it%20to.%20When%20we%20create%20this%20custom%20role%2C%20we%20will%20be%20assigning%20the%20custom%20app%20consent%20policy%20to%20the%20role%20%E2%80%93%20this%20will%20be%20the%20only%20action%20associated%20with%20it.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20must%20create%20a%20custom%20role%20as%20we%20cannot%20scope%20an%20app%20consent%20policy%20to%20a%20group%20or%20user%20directly.%3C%2FP%3E%0A%3CP%3EUsing%20a%20code%20block%20from%20our%20public%20documentation%2C%20we%20are%20going%20to%20build%20this%20role%20through%20PowerShell%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%23%20Basic%20role%20information%0A%24displayName%20%3D%20%22Fabrikam%20B2C%20Role%22%0A%24description%20%3D%20%22For%20access%20to%20Fabrikam%20B2C%20Application.%22%0A%24templateId%20%3D%20(New-Guid).Guid%0A%20%0A%23%20Set%20of%20permissions%20to%20grant%0A%24allowedResourceAction%20%3D%0A%40(%0A%20%22microsoft.directory%2FservicePrincipals%2FmanagePermissionGrantsForSelf.fabrikam-b2c-app%22%0A%20%20)%0A%24rolePermissions%20%3D%20%40%7B'allowedResourceActions'%3D%20%24allowedResourceAction%7D%0A%20%20%0A%23%20Create%20new%20custom%20admin%20role%0A%24customAdmin%20%3D%20New-AzureADMSRoleDefinition%20-RolePermissions%20%24rolePermissions%20%60%0A%20-DisplayName%20%24displayName%20-Description%20%24description%20%60%0A%20-TemplateId%20%24templateId%20-IsEnabled%20%24true%20%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Eric_Woodruff_5-1612548756208.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F252760iA40BB617AD2D2636%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Eric_Woodruff_5-1612548756208.png%22%20alt%3D%22Eric_Woodruff_5-1612548756208.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELooking%20at%20the%20code%20presented%2C%20line%209%20is%20the%20important%20piece%2C%20where%20we%20can%20see%20that%20we%20are%20giving%20the%20ability%20to%20manage%20permission%20grants%20for%20self%20to%20the%20role%2C%20relative%20to%20what%20applications%20would%20then%20be%20specified%20within%20the%20policy.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOne%20thing%20to%20point%20out%20for%20this%20snippet%20of%20code%20%E2%80%93%20if%20you%20refer%20to%20documentation%20on%20setting%20this%2C%20we%20refer%20to%20policy%20ID%2C%20which%20in%20this%20case%20is%20the%20%3CSTRONG%3Ename%3C%2FSTRONG%3E%2C%20as%20you%20can%20see%20in%20our%20example%20fabrikam-b2c-app.%20People%20(including%20this%20author)%20may%20initially%20get%20tripped%20up%20and%20think%20ID%20%3D%20something%20like%20the%20Object%20ID%20for%20the%20policy%2C%20which%20is%20not%20was%20we%20are%20referencing%20in%20this%20case.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-132834382%22%20id%3D%22toc-hId--1411168715%22%3E4%20%7C%20Assign%20Users%20to%20the%20Custom%20Role%3C%2FH3%3E%0A%3CP%3EThe%20last%20step%20is%20to%20assign%20users%20to%20the%20custom%20role.%20From%20a%20management%20perspective%20it%20may%20seem%20arduous%20to%20think%20about%20having%20to%20assign%20every%20relevant%20user%20in%20your%20organization%20to%20this%20role.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELuckily%2C%20with%20cloud%20the%20ability%20to%20use%20cloud%20groups%20for%20role%20assignment%20(in%20public%20preview%20at%20the%20time%20of%20this%20writing)%2C%20we%20can%20simply%20assign%20a%20group%20to%20this%20role%20%E2%80%93%20for%20my%20test%20tenant%20I%E2%80%99m%20using%20an%20existing%20group%20that%20already%20contains%20all%20the%20relevant%20employees.%20The%20snippet%20to%20assign%20a%20group%20to%20the%20role%20assignment%20is%20as%20follows%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3ENew-AzureADMSRoleAssignment%20-ResourceScope%20%22%2F%22%20-DirectoryScopeId%20%22%2F%22%20%60%0A%20-RoleDefinitionId%20%225001e3d6-015c-44b0-a680-6325e70d9739%22%20%60%0A%20-PrincipalId%20%22e143c731-4dbd-4312-ac6a-2eaac9cef1c3%22%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Eric_Woodruff_6-1612548756215.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F252761i0207204161FF930A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Eric_Woodruff_6-1612548756215.png%22%20alt%3D%22Eric_Woodruff_6-1612548756215.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1337532509%22%20id%3D%22toc-hId-252097920%22%3EEnd%20Result%3C%2FH2%3E%0A%3CP%3ENow%20that%20we%20have%20created%20the%20policy%2C%20assigned%20it%20to%20a%20custom%20role%2C%20and%20have%20users%20scoped%20to%20that%20role%20by%20group%20membership%2C%20they%20are%20now%20able%20to%20consent%20to%20just%20this%20one%20specific%20application%2C%20without%20requiring%20administrative%20consent%20grant.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Eric_Woodruff_7-1612548756219.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F252762iCED698C7BF2B7E1C%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Eric_Woodruff_7-1612548756219.png%22%20alt%3D%22Eric_Woodruff_7-1612548756219.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3ENow%20we%20are%20in%20business%20with%20delegated%20application%20consent%20for%20just%20this%20one%20application.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%221%202%203%204%205%206%207%22%3EDisclaimer%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%221%202%203%204%205%206%207%22%3EThe%20sample%20scripts%20are%20not%20supported%20under%20any%20Microsoft%20standard%20support%20program%20or%20service.%20The%20sample%20scripts%20are%20provided%20AS%20IS%20without%20warranty%20of%20any%20kind.%20Microsoft%20further%20disclaims%20all%20implied%20warranties%20including%2C%20without%20limitation%2C%20any%20implied%20warranties%20of%20merchantability%20or%20of%20fitness%20for%20a%20particular%20purpose.%20The%20entire%20risk%20arising%20out%20of%20the%20use%20or%20performance%20of%20the%20sample%20scripts%20and%20documentation%20remains%20with%20you.%20In%20no%20event%20shall%20Microsoft%2C%20its%20authors%2C%20or%20anyone%20else%20involved%20in%20the%20creation%2C%20production%2C%20or%20delivery%20of%20the%20scripts%20be%20liable%20for%20any%20damages%20whatsoever%20(including%2C%20without%20limitation%2C%20damages%20for%20loss%20of%20business%20profits%2C%20business%20interruption%2C%20loss%20of%20business%20information%2C%20or%20other%20pecuniary%20loss)%20arising%20out%20of%20the%20use%20of%20or%20inability%20to%20use%20the%20sample%20scripts%20or%20documentation%2C%20even%20if%20Microsoft%20has%20been%20advised%20of%20the%20possibility%20of%20such%20damages.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2115812%22%20slang%3D%22en-US%22%3E%3CP%3EDeep%20dive%20into%20configuring%20custom%20application%20consent%20policies%20in%20Azure%20Active%20Directory%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22logo2.png%22%20style%3D%22width%3A%20382px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F252773i32B9F55C702A8E9D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22logo2.png%22%20alt%3D%22logo2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2115812%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EEricWoodruff%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

 

Hey folks, Eric Woodruff here – a Customer Engineer who lives in the world of Azure Active Directory.

 

Today we are going to be examining custom app consent policies in Azure Active Directory, and how you can leverage them for some advanced and granular consent policies within your Azure AD tenant.

 

We won’t really be diving into the basics of application consent today, but it’s increasingly becoming a topic of discussion with customers, to ensure that they are keeping their organization secure and that they have insight and control over what applications their end users are accessing with their organization identities. For a bit more background on application consent, as well as why you should be aware of it within your organization, refer to some of our docs – and perhaps the future will hold further blog posts discussing such.

Configure how end-users consent to applications using Azure AD | Microsoft Docs

Detect and Remediate Illicit Consent Grants - Office 365 | Microsoft Docs

 

Background

For customers that want to restrict the ability for end users to grant consent to applications, the trade-off between security and usability starts to come into play.

 

We have multiple options to help customers try and find this balance – the ability for organizations to specify permissions considered low impact, or from verified publishers. And we have the ability for organizations to enable the preview feature of admin consent workflows – when a user needs an app, a request will be sent to specified administrators to approve (or deny) it. And for most of our customers these solutions fit their business needs.

 

We have a subset of customers that wish to restrict the ability for end users to be able to onboard new applications into the organization and require that the end users still must consent to the delegated permissions before being able to use the application. With a custom app consent policy, we can meet these needs.

 

Problem Scenario

In our demo Azure AD tenant, we want to allow for users to be able to perform a delegated user consent for the Fabrikam B2C Enterprise Application – in your Azure AD tenant this could be any Enterprise App that requires user consent.

 

We have already gone through the process of onboarding the application into Azure AD, but we still want to require the users to accept the delegated permissions when accessing this application.

 

In our tenant, we have disabled the ability for users to consent to apps accessing data on their behalf. And while the admin consent workflow would allow for granting permissions, that process also performs an Admin consent grant, so subsequently users would be able to access the application without needing to consent to the permissions themselves.

 

Eric_Woodruff_0-1612548756170.png

The app consent approval workflow that just won’t fit our business requirements.

 

Implementation

 

1 | Revoke Any Existing Permissions

Depending on how the application was onboarded, there may be a pre-existing set of permissions already accepted that we may want to remove; if this does not fit your case then just move on to step 2.

 

Luckily, Azure AD already provides an easy means of giving you a PowerShell snippet to revoke existing approvals. From within the Enterprise Application, if you select Permissions under the Security section of the applications blade, and within the details blade, select Review permissions at the top, and then select This application has more permissions than I want. There will be a PowerShell script presented that you can run to remove all pre-existing permission grants.

 

2 | Build A Custom Application Consent Policy

 

2.1 | Examining Existing Policies

Now that we have a fresh slate for our application, we are ready to build a custom app consent policy.

 

Ensure that we are using the latest version of the Azure AD Preview PowerShell module, connect to your Azure AD tenant.

 

After connecting to Azure AD, we can get familiar with the policies that already exist in our tenant; all customers will have some out of the box consent policies within their tenant, as we can see when we enumerate them:

 

Get-AzureADMSPermissionGrantPolicy | ft Id,DisplayName,Description

 

 

Eric_Woodruff_1-1612548756180.png


2.2 | Create New Policy

Now that we see what policies already exist, we can create our new policy:

 

New-AzureADMSPermissionGrantPolicy `
 -Id "fabrikam-b2c-app" `
 -DisplayName "Fabrikam B2C App Consent Policy" `
 -Description "Custom consent policy for Fabrikam B2C App."

 

Eric_Woodruff_2-1612548756186.png

 

After creation, we can enumerate our policies again and verify creation:

Eric_Woodruff_3-1612548756194.png

 

2.3 | Create Policy Conditions

Now that we have the policy, we must create the policy conditions that will be defined within it. When defining our policy, we have several conditions we can use to create include and/or exclude conditions. I won’t be diving into all those conditions here, but they are notated in our documentation:

Manage app consent policies in Azure AD | Microsoft Docs

 

In our case, we are going to build a policy that is specific to the ClientApplicationIds condition, which will contain the Application ID that is assigned to the Fabrikam B2C Application in our tenant – the Application ID will be unique for each application in a tenant.

 

New-AzureADMSPermissionGrantConditionSet `
 -PolicyId "fabrikam-b2c-app" `
 -ConditionSetType "includes" `
 -PermissionType "delegated" `
 -ClientApplicationIds "<application-id>"

 

Eric_Woodruff_4-1612548756201.png

 

3 | Create a Custom Azure AD Role

Now that we have our policy defined, we need to create a custom role within Azure AD to assign it to. When we create this custom role, we will be assigning the custom app consent policy to the role – this will be the only action associated with it.

 

We must create a custom role as we cannot scope an app consent policy to a group or user directly.

Using a code block from our public documentation, we are going to build this role through PowerShell:

 

# Basic role information
$displayName = "Fabrikam B2C Role"
$description = "For access to Fabrikam B2C Application."
$templateId = (New-Guid).Guid
 
# Set of permissions to grant
$allowedResourceAction =
@(
 "microsoft.directory/servicePrincipals/managePermissionGrantsForSelf.fabrikam-b2c-app"
  )
$rolePermissions = @{'allowedResourceActions'= $allowedResourceAction}
	 
# Create new custom admin role
$customAdmin = New-AzureADMSRoleDefinition -RolePermissions $rolePermissions `
 -DisplayName $displayName -Description $description `
 -TemplateId $templateId -IsEnabled $true 

 

Eric_Woodruff_5-1612548756208.png

 

Looking at the code presented, line 9 is the important piece, where we can see that we are giving the ability to manage permission grants for self to the role, relative to what applications would then be specified within the policy.

 

One thing to point out for this snippet of code – if you refer to documentation on setting this, we refer to policy ID, which in this case is the name, as you can see in our example fabrikam-b2c-app. People (including this author) may initially get tripped up and think ID = something like the Object ID for the policy, which is not was we are referencing in this case.

 

4 | Assign Users to the Custom Role

The last step is to assign users to the custom role. From a management perspective it may seem arduous to think about having to assign every relevant user in your organization to this role.

 

Luckily, with cloud the ability to use cloud groups for role assignment (in public preview at the time of this writing), we can simply assign a group to this role – for my test tenant I’m using an existing group that already contains all the relevant employees. The snippet to assign a group to the role assignment is as follows:

 

New-AzureADMSRoleAssignment -ResourceScope "/" -DirectoryScopeId "/" `
 -RoleDefinitionId "5001e3d6-015c-44b0-a680-6325e70d9739" `
 -PrincipalId "e143c731-4dbd-4312-ac6a-2eaac9cef1c3"

 

Eric_Woodruff_6-1612548756215.png

 

End Result

Now that we have created the policy, assigned it to a custom role, and have users scoped to that role by group membership, they are now able to consent to just this one specific application, without requiring administrative consent grant.

 

Eric_Woodruff_7-1612548756219.png

Now we are in business with delegated application consent for just this one application.

 

 

 

 

Disclaimer

The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.