Home

Example of retrieving Azure AD access reviews via Microsoft Graph

%3CLINGO-SUB%20id%3D%22lingo-sub-236096%22%20slang%3D%22en-US%22%3EExample%20of%20retrieving%20Azure%20AD%20access%20reviews%20via%20Microsoft%20Graph%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-236096%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20Azure%20AD%20access%20reviews%20feature%20now%20has%20an%20API%20in%20the%20Microsoft%20Graph%20beta%20endpoint.%26nbsp%3B%20The%20list%20of%20API%20methods%20is%20at%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdeveloper.microsoft.com%2Fen-us%2Fgraph%2Fdocs%2Fapi-reference%2Fbeta%2Fresources%2Faccessreviews_root%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdeveloper.microsoft.com%2Fen-us%2Fgraph%2Fdocs%2Fapi-reference%2Fbeta%2Fresources%2Faccessreviews_root%3C%2FA%3E%3C%2FSPAN%3E.%26nbsp%3B%20While%20we%20are%20in%20progress%20of%20adding%20access%20reviews%20to%20Azure%20AD%20PowerShell%20and%20examples%20of%20using%20access%20reviews%20from%20other%20development%20platforms%20to%20our%20documentation%2C%20the%20following%20code%20sample%20may%20be%20of%20interest.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1647530744%22%20id%3D%22toc-hId-1703718245%22%3EAzure%20AD%20access%20reviews%20data%20model%3C%2FH2%3E%0A%3CP%3EThe%20Azure%20AD%20access%20reviews%20feature%20adds%20the%20following%20resource%20types%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EaccessReview%3A%20represents%20an%20access%20review.%26nbsp%3B%20This%20can%20be%20a%20one-time%20review%2C%20a%20recurring%20review%20series%2C%20or%20an%20instance%20of%20a%20recurring%20review.%3C%2FLI%3E%0A%3CLI%3EbusinessFlowTemplate%3A%20the%20business%20flow%20template%20determines%20the%20type%20resource%20on%20which%20an%20access%20review%20is%20to%20be%20performed.%20The%20identifier%20of%20a%20template%2C%20such%20as%20to%20review%20guest%20members%20of%20a%20group%2C%20is%20supplied%20by%20the%20caller%20when%20creating%20an%20access%20review.%20(The%20business%20flow%20template%20objects%20are%20read%20only%2C%20they%20are%20automatically%20generated%20when%20the%20global%20administrator%20onboards%20the%20tenant%20to%20use%20the%20access%20reviews%20feature.%20No%20additional%20business%20flow%20templates%20can%20be%20created.)%3C%2FLI%3E%0A%3CLI%3Eprogram%3A%20represents%20an%20Azure%20AD%20access%20review%20program.%20A%20program%20is%20a%20container%2C%20holding%20program%20controls.%20A%20tenant%20can%20have%20one%20or%20more%20programs.%26nbsp%3B%20Each%20control%20links%20an%20access%20review%20to%20a%20program%2C%20to%20make%20it%20easier%20to%20locate%20related%20access%20reviews.%26nbsp%3B%20Each%20tenant%20that%20has%20onboarded%20Azure%20AD%20access%20reviews%20has%20one%20program%2C%20%60Default%20program%60.%26nbsp%3B%20A%20global%20administrator%20can%20create%20additional%20programs%2C%20for%20example%20to%20represent%20compliance%20initiatives.%3C%2FLI%3E%0A%3CLI%3EprogramControl%3A%20represents%20a%20control%2C%20which%20links%20an%20access%20review%20to%20a%20particular%20program.%3C%2FLI%3E%0A%3CLI%3EprogramControlType%3A%20the%20program%20control%20type%20is%20used%20when%20associating%20a%20control%20to%20a%20program%2C%20to%20indicate%20the%20type%20of%20access%20review%20the%20control%20is%20for.%20(The%20program%20control%20type%20objects%20are%20read%20only%2C%20they%20are%20automatically%20generated%20when%20the%20global%20administrator%20onboards%20the%20tenant%20to%20use%20the%20access%20reviews%20feature.%26nbsp%3B%20No%20additional%20program%20control%20types%20can%20be%20created.)%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22toc-hId--904626217%22%20id%3D%22toc-hId--848438716%22%3EUnderstanding%20authorization%20requirements%3C%2FH2%3E%0A%3CP%3EThe%20Azure%20AD%20access%20reviews%20API%20performs%20three%20checks%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EFirst%2C%20has%20the%20tenant%20onboarded%20to%20the%20feature%20%E2%80%93%20Azure%20AD%20access%20reviews%20or%2C%20in%20the%20case%20of%20access%20reviews%20of%20Azure%20AD%20roles%2C%20Azure%20AD%20PIM.%20Both%20of%20these%20features%20are%20included%20in%20Azure%20AD%20Premium%20P2%2C%20and%20require%20the%20administrator%20to%20have%20used%20the%20features%20at%20least%20once%20in%20order%20to%20permit%20the%20APIs%20to%20be%20called.%20If%20you%20have%20not%20already%20used%20Azure%20AD%20access%20reviews%2C%20the%20section%20%E2%80%9CEnable%20Azure%20AD%20access%20reviews%20in%20your%20tenant%E2%80%9D%20below%20onboards%20the%20Azure%20AD%20access%20reviews%20feature%20so%20you%20can%20try%20out%20the%20APIs.%3C%2FLI%3E%0A%3CLI%3ESecond%2C%20does%20the%20application%20have%20the%20necessary%20permissions.%20The%20permissions%20available%20for%20these%20APIs%20are%3A%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CUL%3E%0A%3CLI%3EAccessReview.Read.All%3A%20read%20access%20reviews%3C%2FLI%3E%0A%3CLI%3EAccessReview.ReadWrite.All%3A%20read%2C%20create%2C%20update%20and%20delete%20access%20reviews%3C%2FLI%3E%0A%3CLI%3EProgramControl.Read.All%3A%20read%20programs%20and%20controls%3C%2FLI%3E%0A%3CLI%3EProgramControl.ReadWrite.All%3A%20read%2C%20create%2C%20update%20and%20delete%20programs%20and%20controls%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EIf%20you%20do%20not%20already%20have%20those%20permissions%20on%20an%20application%2C%20the%20section%20%E2%80%9CRegister%20an%20Azure%20AD%20application%20which%20can%20call%20the%20access%20reviews%20Graph%20API%E2%80%9D%20below%20creates%20a%20new%20application%20and%20assigns%20it%20read%20permissions.%26nbsp%3B%20(You%20can%20change%20the%20scenario%20to%20assign%20it%20read%20and%20write%20permission).%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EThird%2C%20does%20the%20user%20have%20the%20necessary%20permissions.%20%26nbsp%3BThis%20is%20determined%20by%20the%20calling%20user%E2%80%99s%20directory%20role%3A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CTABLE%3E%0A%3CTBODY%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22162%22%3E%3CP%3E%3CSTRONG%3ETarget%20Resource%3C%2FSTRONG%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22180%22%3E%3CP%3E%3CSTRONG%3EDesired%20Operation%3C%2FSTRONG%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22234%22%3E%3CP%3E%3CSTRONG%3ERequired%20directory%20role%20of%20the%20user%2C%20in%20addition%20to%20the%20application%20permission%3C%2FSTRONG%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22162%22%20rowspan%3D%222%22%3E%3CP%3EAccess%20review%20of%20an%20Azure%20AD%20role%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22180%22%3E%3CP%3ERead%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22234%22%3E%3CP%3EGlobal%20Administrator%2C%3CBR%20%2F%3E%20Security%20Administrator%2C%3CBR%20%2F%3E%20Security%20Reader%20or%20%3CBR%20%2F%3E%20Privileged%20Role%20Administrator%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22180%22%3E%3CP%3ECreate%2C%20Update%20or%20Delete%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22234%22%3E%3CP%3EGlobal%20Administrator%20or%20%3CBR%20%2F%3E%20Privileged%20Role%20Administrator%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22162%22%20rowspan%3D%222%22%3E%3CP%3EAccess%20review%20of%20a%20group%20or%20app%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22180%22%3E%3CP%3ERead%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22234%22%3E%3CP%3EGlobal%20Administrator%2C%3CBR%20%2F%3E%20Security%20Administrator%2C%3CBR%20%2F%3E%20Security%20Reader%20or%20%3CBR%20%2F%3E%20User%20Administrator%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22180%22%3E%3CP%3ECreate%2C%20Update%20or%20Delete%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22234%22%3E%3CP%3EGlobal%20Administrator%20or%20%3CBR%20%2F%3E%20User%20Administrator%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22162%22%20rowspan%3D%222%22%3E%3CP%3EPrograms%20or%20controls%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22180%22%3E%3CP%3ERead%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22234%22%3E%3CP%3EGlobal%20Administrator%2C%3CBR%20%2F%3E%20Security%20Administrator%2C%3CBR%20%2F%3E%20Security%20Reader%20or%20%3CBR%20%2F%3E%20User%20Administrator%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22180%22%3E%3CP%3ECreate%2C%20Update%20or%20Delete%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22234%22%3E%3CP%3EGlobal%20Administrator%20or%20%3CBR%20%2F%3E%20User%20Administrator%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3C%2FTBODY%3E%0A%3C%2FTABLE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-838184118%22%20id%3D%22toc-hId-894371619%22%3EEnable%20Azure%20AD%20access%20reviews%20in%20your%20tenant%3C%2FH2%3E%0A%3CP%3EThis%20example%20assumes%20you%20have%20already%20onboarded%20Azure%20AD%20access%20reviews%20in%20your%20tenant%20directory.%26nbsp%3B%20If%20you%20have%20already%20done%20so%2C%20then%20skip%20to%20the%20next%20section%20%E2%80%9CRegister%20an%20Azure%20AD%20application%20which%20has%20permissions%20to%20call%20the%20access%20reviews%20API%20in%20Graph%E2%80%9D.%26nbsp%3B%20Otherwise%2C%20continue%20with%20these%20steps%20to%20ensure%20the%20feature%20is%20onboarded%20so%20the%20APIs%20will%20return%20some%20data.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ELog%20into%20the%20Azure%20portal%20as%20a%20global%20administrator.%3C%2FLI%3E%0A%3CLI%3EEnsure%20that%20your%20organization%20has%20Azure%20AD%20Premium%20P2%20or%20EMS%20E5%20subscription%20active.%20If%20not%2C%20click%20on%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fportal.azure.com%2F%23blade%2FMicrosoft_AAD_IAM%2FTryBuyProductBlade%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fportal.azure.com%2F%23blade%2FMicrosoft_AAD_IAM%2FTryBuyProductBlade%3C%2FA%3E%3C%2FSPAN%3E%20and%20activate%20a%20trial%20of%20Enterprise%20Mobility%20%2B%20Security%20E5.%20Otherwise%2C%20if%20your%20organization%20has%20an%20active%20subscription%2C%20continue%20at%20the%20next%20step.%3C%2FLI%3E%0A%3CLI%3ENavigate%20to%20the%20Azure%20AD%20extension%2C%20and%20click%20on%20%E2%80%9CAccess%20reviews%E2%80%9D%20on%20the%20right%20hand%20side%20under%20%E2%80%9COther%20capabilities%E2%80%9D.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20377px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F43562i7A6748FD060BC9E3%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%223other.png%22%20title%3D%223other.png%22%20%2F%3E%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLI%3E%0A%3CLI%3EIf%20you%20have%20not%20already%20onboarded%20Azure%20AD%20access%20reviews%20in%20your%20organization%2C%20onboard%20it%20now.%3C%2FLI%3E%0A%3CLI%3EClick%20on%20%E2%80%9CPrograms%E2%80%9D%20and%20ensure%20there%20is%20at%20least%20one%20program%20listed.%26nbsp%3B%20At%20this%20point%20you%20can%20create%20additional%20access%20reviews%20if%20you%20wish.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1713972843%22%20id%3D%22toc-hId--1657785342%22%3ERegister%20an%20Azure%20AD%20application%20which%20has%20permissions%20to%20call%20the%20access%20reviews%20API%20in%20Graph%3C%2FH2%3E%0A%3CP%3EThe%20Graph%20authorization%20model%20requires%20that%20an%20application%20must%20be%20consented%20by%20a%20user%20or%20administrator%20prior%20to%20accessing%20an%20organization%E2%80%99s%20data.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%226%22%3E%0A%3CLI%3ELog%20into%20the%20Azure%20portal%20as%20a%20global%20administrator.%3C%2FLI%3E%0A%3CLI%3ENavigate%20to%20the%20Azure%20AD%20extension%2C%20and%20click%20on%20%E2%80%9CApp%20registrations%E2%80%9D%20in%20the%20MANAGE%20section%2C%20to%20land%20at%20the%20page%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fportal.azure.com%2F%23blade%2FMicrosoft_AAD_IAM%2FActiveDirectoryMenuBlade%2FRegisteredApps%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fportal.azure.com%2F%23blade%2FMicrosoft_AAD_IAM%2FActiveDirectoryMenuBlade%2FRegisteredApps%3C%2FA%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3EClick%20on%20%E2%80%9CNew%20application%20registration%E2%80%9D%20button%20at%20the%20top%20of%20the%20page.%3C%2FLI%3E%0A%3CLI%3EProvide%20a%20name%20for%20the%20application%20that%20is%20different%20from%20any%20other%20application%20in%20your%20tenant%E2%80%99s%20directory%20(e.g.%2C%20%E2%80%9Cgraphsample%E2%80%9D)%2C%20change%20the%20Application%20type%20to%20Native%2C%20and%20provide%20the%20following%20as%20the%20Redirect%20URI%3A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3Eurn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%2210%22%3E%0A%3CLI%3EClick%20%E2%80%9CCreate%E2%80%9D.%3C%2FLI%3E%0A%3CLI%3EWhen%20the%20application%20is%20registered%2C%20copy%20the%20Application%20ID%20value%2C%20and%20save%20the%20value%20for%20later.%3C%2FLI%3E%0A%3CLI%3EClick%20on%20Settings%2C%20then%20click%20on%20%E2%80%9CRequired%20permissions%E2%80%9D.%3C%2FLI%3E%0A%3CLI%3EClick%20on%20%E2%80%9CAdd%E2%80%9D.%20Click%20on%20%E2%80%9CSelect%20an%20API%E2%80%9D%2C%20click%20on%20%E2%80%9CMicrosoft%20Graph%E2%80%9D%2C%20and%20then%20click%20%E2%80%9CSelect%E2%80%9D.%3C%2FLI%3E%0A%3CLI%3EAzure%20AD%20access%20reviews%20uses%20the%20following%20delegated%20permissions%3A%20Read%20all%20access%20reviews%20that%20use%20can%20access%2C%20Manage%20all%20access%20reviews%20that%20user%20can%20access%2C%20Read%20all%20programs%20that%20user%20can%20access%2C%20and%20Manage%20all%20programs%20that%20user%20can%20access.%20This%20example%20application%20requires%20only%20the%20permissions%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Read%20all%20access%20reviews%20that%20user%20can%20access%3CBR%20%2F%3E%20Read%20all%20programs%20that%20user%20can%20access%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Put%20a%20checkbox%20by%20those%20two%20permissions%2C%20and%20click%20%E2%80%9CSelect%E2%80%9D.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20897px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F43561iAFA0096423291BD5%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%2214delegated.png%22%20title%3D%2214delegated.png%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3EClick%20%E2%80%9CDone%E2%80%9D.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH2%20id%3D%22toc-hId-28837492%22%20id%3D%22toc-hId-85024993%22%3E(Sample%20only)%20Ensure%20PowerShell%20and%20the%20ADAL%20libraries%20are%20on%20your%20computer%3C%2FH2%3E%0A%3CP%3EThe%20Microsoft%20Graph%20requires%20the%20application%20calling%20it%20to%20have%20an%20access%20token.%3C%2FP%3E%0A%3CP%3EIn%20this%20example%2C%20the%20sample%20code%20to%20use%20the%20API%20will%20leverage%20the%20ADAL%20library%20which%20is%20automatically%20installed%20when%20using%20Azure%20AD%20PowerShell%20cmdlets.%3C%2FP%3E%0A%3COL%20start%3D%2216%22%3E%0A%3CLI%3EEnsure%20that%20you%20have%20PowerShell%203.0%20or%20later%2C%20and%20.NET%20Framework%204.5%20installed%20on%20your%20computer.%3C%2FLI%3E%0A%3CLI%3EEnsure%20that%20you%20have%20either%20the%20Azure%20AD%20PowerShell%20v2%20General%20Availability%20or%20Preview%20modules%20installed%20on%20your%20computer.%20If%20not%2C%20more%20information%20on%20how%20to%20install%20them%20is%20at%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fazure%2Factive-directory%2Finstall-adv2%3Fview%3Dazureadps-2.0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fazure%2Factive-directory%2Finstall-adv2%3Fview%3Dazureadps-2.0%3C%2FA%3E%3C%2FSPAN%3E.%20Try%20using%20Connect-AzureAD%20to%20ensure%20that%20you%20can%20authenticate%20to%20Azure%20AD%20as%20a%20global%20administrator.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH2%20id%3D%22toc-hId-1771647827%22%20id%3D%22toc-hId-1827835328%22%3ERetrieving%20the%20token%20and%20calling%20the%20API%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%2218%22%3E%0A%3CLI%3ECreate%20a%20file%20named%20%E2%80%9Caccess-reviews-example1.ps1%E2%80%9D%20whose%20context%20in%20the%20sample%20PowerShell%20from%20the%20end%20of%20this%20post.%3C%2FLI%3E%0A%3CLI%3EStart%20PowerShell.%3C%2FLI%3E%0A%3CLI%3EChange%20to%20the%20directory%20where%20the%20access-reviews-example1.ps1%20script%20is%20located.%3C%2FLI%3E%0A%3CLI%3EInvoke%20the%20script%2C%20providing%20on%20the%20command%20line%20-User%20with%20the%20User%20principal%20name%20(UPN)%20of%20a%20global%20administrator%2C%20and%20-ClientId%20with%20the%20application%20ID%20value%20from%20earlier.%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20For%20example%2C%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20.%5Caccess-reviews-example1.ps1%20-User%20ga%40contoso.onmicrosoft.com%3CBR%20%2F%3E%20-ClientId%20280d7b83-8d0a-4ee7-8f1a-064ec36d1fa1%3C%2FLI%3E%0A%3CLI%3EWhen%20the%20script%20is%20run%20for%20the%20first%20time%20in%20a%20PowerShell%20session%2C%20you%20will%20be%20asked%20to%20authenticate.%26nbsp%3B%20For%20the%20purposes%20of%20this%20example%2C%20ensure%20that%20you%20sign%20in%20as%20a%20global%20administrator.%3C%2FLI%3E%0A%3CLI%3EAfter%20authenticating%2C%20the%20first%20time%20the%20script%20is%20run%20for%20a%20particular%20application%2C%20you%20will%20be%20prompted%20to%20consent%20the%20application%20use%20of%20permissions.%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20472px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F43560i298B68D18C46F2CF%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22consent.png%22%20title%3D%22consent.png%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3COL%20start%3D%2224%22%3E%0A%3CLI%3EOnce%20consented%2C%20the%20script%20will%20use%20the%20token%20to%20call%20Microsoft%20Graph%20and%20retrieve%20programs%2C%20controls%2C%20business%20flow%20templates%20and%20access%20reviews%2C%20and%20write%20a%20summary%20of%20them%20to%20the%20PowerShell%20window.%3C%2FLI%3E%0A%3CLI%3ENote%20that%20the%20authorization%20is%20only%20applicable%20to%20the%20global%20administrator%20who%20consented%20to%20the%20application%2C%20and%20only%20for%20that%20tenant.%20If%20other%20users%20in%20the%20organization%20or%20in%20other%20applications%20also%20wish%20to%20use%20the%20application%2C%20additional%20steps%20are%20required%20for%20admin%20consent.%26nbsp%3B%20See%20the%20article%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Fdevelop%2Factive-directory-devhowto-multi-tenant-overview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Fdevelop%2Factive-directory-devhowto-multi-tenant-overview%3C%2FA%3E%3C%2FSPAN%3E%20for%20more%20information%20on%20admin%20consent%20in%20applications.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--780509134%22%20id%3D%22toc-hId--724321633%22%3ESample%20(PowerShell)%3C%2FH2%3E%0A%3CPRE%3E%23%20Example%20for%20using%20Azure%20AD%20access%20reviews%20in%20Microsoft%20Graph%0A%23%0A%23%20This%20material%20is%20provided%20%22AS-IS%22%20and%20has%20no%20warranty.%0A%23%20%0A%23%20Last%20updated%20August%2022%2C%202018%0A%23%0A%23%20This%20example%20is%20adapted%20from%20the%20documentation%20example%20located%20at%20%0A%23%20https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fintune%2Fintune-graph-apis%0A%23%0A%23%0A%0AParam(%0A%20%20%20%20%5BParameter(Mandatory%3D%24true)%5D%5Bstring%5D%24User%2C%0A%0A%20%20%20%20%5BParameter(Mandatory%3D%24true)%5D%5Bstring%5D%24ClientId%0A)%0A%0A%0A%23%20from%20Intune%20graph%20API%20samples%0A%0Afunction%20Get-GraphExampleAuthToken%20%7B%0A%20%20%20%20%5Bcmdletbinding()%5D%0A%20%20%20%20param%0A%20%20%20%20(%0A%20%20%20%20%20%20%20%20%5BParameter(Mandatory%20%3D%20%24true)%5D%0A%20%20%20%20%20%20%20%20%24User%2C%0A%0A%20%20%20%20%20%20%20%20%5BParameter(Mandatory%20%3D%20%24true)%5D%0A%20%20%20%20%20%20%20%20%24ClientId%2C%0A%0A%20%20%20%20%20%20%20%20%5BParameter()%5D%0A%20%20%20%20%20%20%20%20%24TenantDomain%0A%20%20%20%20)%0A%0A%20%20%20%20%24userUpn%20%3D%20New-Object%20%22System.Net.Mail.MailAddress%22%20-ArgumentList%20%24User%0A%20%20%20%20%24tenant%20%3D%20%24userUpn.Host%0A%0A%20%20%20%20if%20(%24TenantDomain%20-ne%20%24null)%20%7B%0A%20%20%20%20%20%20%20%20%24tenant%20%3D%20%24TenantDomain%0A%20%20%20%20%7D%0A%0A%20%20%20%20Write-Verbose%20%22Checking%20for%20AzureAD%20module...%22%0A%0A%20%20%20%20%24AadModule%20%3D%20Get-Module%20-Name%20%22AzureAD%22%20-ListAvailable%0A%20%20%20%20if%20(%24AadModule%20-eq%20%24null)%20%7B%0A%20%20%20%20%20%20%20%20Write-Host%20%22AzureAD%20PowerShell%20module%20not%20found%2C%20looking%20for%20AzureADPreview%22%0A%20%20%20%20%20%20%20%20%24AadModule%20%3D%20Get-Module%20-Name%20%22AzureADPreview%22%20-ListAvailable%0A%20%20%20%20%7D%0A%0A%20%20%20%20if%20(%24AadModule%20-eq%20%24null)%20%7B%0A%20%20%20%20%20%20%20%20write-host%0A%20%20%20%20%20%20%20%20write-host%20%22AzureAD%20Powershell%20module%20not%20installed...%22%20-f%20Red%0A%20%20%20%20%20%20%20%20write-host%20%22Install%20by%20running%20'Install-Module%20AzureAD'%20or%20'Install-Module%20AzureADPreview'%20from%20an%20elevated%20PowerShell%20prompt%22%20-f%20Yellow%0A%20%20%20%20%20%20%20%20write-host%20%22Script%20can't%20continue...%22%20-f%20Red%0A%20%20%20%20%20%20%20%20write-host%0A%20%20%20%20%20%20%20%20exit%0A%20%20%20%20%7D%0A%0A%20%20%20%20%23%20Getting%20path%20to%20ActiveDirectory%20Assemblies%0A%20%20%20%20%23%20If%20the%20module%20count%20is%20greater%20than%201%20find%20the%20latest%20version%0A%0A%20%20%20%20if%20(%24AadModule.count%20-gt%201)%20%7B%0A%20%20%20%20%20%20%20%20%24Latest_Version%20%3D%20(%24AadModule%20%7C%20select%20version%20%7C%20Sort-Object)%5B-1%5D%0A%20%20%20%20%20%20%20%20%24aadModule%20%3D%20%24AadModule%20%7C%20%3F%20%7B%20%24_.version%20-eq%20%24Latest_Version.version%20%7D%0A%20%20%20%20%20%20%20%20%24adal%20%3D%20Join-Path%20%24AadModule.ModuleBase%20%22Microsoft.IdentityModel.Clients.ActiveDirectory.dll%22%0A%20%20%20%20%20%20%20%20%24adalforms%20%3D%20Join-Path%20%24AadModule.ModuleBase%20%22Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll%22%0A%20%20%20%20%7D%0A%0A%20%20%20%20else%20%7B%0A%20%20%20%20%20%20%20%20%24adal%20%3D%20Join-Path%20%24AadModule.ModuleBase%20%22Microsoft.IdentityModel.Clients.ActiveDirectory.dll%22%0A%20%20%20%20%20%20%20%20%24adalforms%20%3D%20Join-Path%20%24AadModule.ModuleBase%20%22Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll%22%0A%20%20%20%20%7D%0A%0A%20%20%20%20%5BSystem.Reflection.Assembly%5D%3A%3ALoadFrom(%24adal)%20%7C%20Out-Null%0A%20%20%20%20%5BSystem.Reflection.Assembly%5D%3A%3ALoadFrom(%24adalforms)%20%7C%20Out-Null%0A%0A%20%20%0A%20%20%20%20%24redirectUri%20%3D%20%22urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob%22%0A%20%20%20%20%24resourceAppIdURI%20%3D%20%22https%3A%2F%2Fgraph.microsoft.com%22%0A%0A%20%20%20%20%24authority%20%3D%20%22https%3A%2F%2Flogin.microsoftonline.com%2F%24Tenant%22%0A%0A%20%20%20%20try%20%7B%0A%20%20%20%20%20%20%20%20%24authContext%20%3D%20New-Object%20%22Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext%22%20-ArgumentList%20%24authority%0A%20%20%20%20%20%20%20%20%23%20https%3A%2F%2Fmsdn.microsoft.com%2Flibrary%2Fazure%2Fmicrosoft.identitymodel.clients.activedirectory.promptbehavior.aspx%0A%20%20%20%20%20%20%20%20%23%20Change%20the%20prompt%20behaviour%20to%20force%20credentials%20each%20time%3A%20Auto%2C%20Always%2C%20Never%2C%20RefreshSession%0A%20%20%20%20%20%20%20%20%24platformParameters%20%3D%20New-Object%20%22Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformParameters%22%20-ArgumentList%20%22Auto%22%0A%20%20%20%20%20%20%20%20%24userId%20%3D%20New-Object%20%22Microsoft.IdentityModel.Clients.ActiveDirectory.UserIdentifier%22%20-ArgumentList%20(%24User%2C%20%22OptionalDisplayableId%22)%0A%20%20%20%20%20%20%20%20%24authResult%20%3D%20%24authContext.AcquireTokenAsync(%24resourceAppIdURI%2C%20%24ClientId%2C%20%24redirectUri%2C%20%24platformParameters%2C%20%24userId).Result%0A%20%20%20%20%20%20%20%20%23%20If%20the%20accesstoken%20is%20valid%20then%20create%20the%20authentication%20header%0A%20%20%20%20%20%20%20%20if%20(%24authResult.AccessToken)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Creating%20header%20for%20Authorization%20token%0A%20%20%20%20%20%20%20%20%20%20%20%20%24authHeader%20%3D%20%40%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'Content-Type'%20%3D%20'application%2Fjson'%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'Authorization'%20%3D%20%22Bearer%20%22%20%2B%20%24authResult.AccessToken%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'ExpiresOn'%20%3D%20%24authResult.ExpiresOn%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20%24authHeader%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20else%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20Write-Host%0A%20%20%20%20%20%20%20%20%20%20%20%20Write-Host%20%22Authorization%20Access%20Token%20is%20null%2C%20please%20re-run%20authentication...%22%20-ForegroundColor%20Red%0A%20%20%20%20%20%20%20%20%20%20%20%20Write-Host%0A%20%20%20%20%20%20%20%20%20%20%20%20break%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20catch%20%7B%0A%20%20%20%20%20%20%20%20write-host%20%24_.Exception.Message%20-f%20Red%0A%20%20%20%20%20%20%20%20write-host%20%24_.Exception.ItemName%20-f%20Red%0A%20%20%20%20%20%20%20%20write-host%0A%20%20%20%20%20%20%20%20break%0A%20%20%20%20%7D%20%20%20%0A%7D%0A%0A%23%20start%20of%20access%20review%20specific%20example%0A%0Afunction%20Get-GraphExampleProgramControls(%24authHeaders%2C%24programId)%0A%7B%0A%20%20%20%20%24uri1%20%3D%20%22https%3A%2F%2Fgraph.microsoft.com%2Fbeta%2Fprograms('%22%20%2B%20%24programId%20%2B%20%22')%2Fcontrols%22%0A%20%20%20%20Write-Host%20%22GET%20%24uri1%22%0A%0A%20%20%20%20%24resp1%20%3D%20Invoke-WebRequest%20-UseBasicParsing%20-headers%20%24authHeaders%20-Uri%20%24uri1%20-Method%20Get%0A%20%20%20%20%24val1%20%3D%20ConvertFrom-Json%20%24resp1.Content%0A%0A%20%20%20%0A%20%20%20%20foreach%20(%24c%20in%20%24val1.Value)%20%7B%0A%20%20%20%20%20%20%20%20%24cid%20%3D%20%24c.controlId%0A%20%20%20%20%20%20%20%20%24displayname%20%3D%20'%22'%20%2B%20%24c.displayName%20%2B%20'%22'%0A%20%20%20%20%20%20%20%20Write-Host%20%22control%20%24cid%20%24displayname%22%0A%20%20%20%20%7D%0A%0A%7D%0A%0Afunction%20Get-GraphExamplePrograms(%24authHeaders)%20%7B%0A%20%20%20%20%24uri1%20%3D%20%22https%3A%2F%2Fgraph.microsoft.com%2Fbeta%2Fprograms%22%0A%20%20%20%20Write-Host%20%22GET%20%24uri1%22%0A%0A%20%20%20%20%24resp1%20%3D%20Invoke-WebRequest%20-UseBasicParsing%20-headers%20%24authHeaders%20-Uri%20%24uri1%20-Method%20Get%0A%20%20%20%20%24val1%20%3D%20ConvertFrom-Json%20%24resp1.Content%0A%0A%20%20%20%0A%20%20%20%20foreach%20(%24program%20in%20%24val1.Value)%20%7B%0A%20%20%20%20%20%20%20%20%24id%20%3D%20%24program.id%0A%20%20%20%20%20%20%20%20%24displayname%20%3D%20'%22'%20%2B%20%24program.displayName%20%2B%20'%22'%0A%20%20%20%20%20%20%20%20Write-Host%20%22program%20%24id%20%24displayName%22%0A%0A%20%20%20%20%20%20%20%20Get-GraphExampleProgramControls%20%24authHeaders%20%24id%0A%20%20%20%20%20%20%20%20Write-Host%20%22%22%0A%20%20%20%20%7D%0A%0A%7D%0A%0Afunction%20Get-GraphExampleAccessReviewDecisions(%24authHeaders%2C%24arid)%0A%7B%0A%20%20%20%20%24uri1%20%3D%20'https%3A%2F%2Fgraph.microsoft.com%2Fbeta%2FaccessReviews('%20%2B%20%22'%22%20%2B%20%24arid%20%20%2B%20%22')%2Fdecisions%22%0A%20%20%20%20Write-Host%20%22GET%20%24uri1%22%0A%20%20%20%20%24resp1%20%3D%20Invoke-WebRequest%20-UseBasicParsing%20-headers%20%24authHeaders%20-Uri%20%24uri1%20-Method%20Get%0A%20%20%20%20%24val1%20%3D%20ConvertFrom-Json%20%24resp1.Content%0A%0A%20%20%20%20foreach%20(%24ard%20in%20%24val1.Value)%20%7B%0A%20%20%20%20%20%20%20%20%24rr%20%3D%20%24ard.reviewResult%0A%20%20%20%20%20%20%20%20%24upn%20%3D%20%24ard.userPrincipalName%0A%0A%20%20%20%20%20%20%20%20Write-Host%20%22access%20review%20decision%20%24upn%20%24rr%22%0A%20%20%20%20%7D%0A%20%20%20%20Write-Host%20%22%22%0A%7D%0A%0Afunction%20Get-GraphExampleAccessReviewInstances(%24authHeaders%2C%24arid)%0A%7B%0A%20%20%20%20%24uri1%20%3D%20'https%3A%2F%2Fgraph.microsoft.com%2Fbeta%2FaccessReviews('%20%2B%20%22'%22%20%2B%20%24arid%20%20%2B%20%22')%2Finstances%22%0A%20%20%20%20Write-Host%20%22GET%20%24uri1%22%0A%20%20%20%20%24resp1%20%3D%20Invoke-WebRequest%20-UseBasicParsing%20-headers%20%24authHeaders%20-Uri%20%24uri1%20-Method%20Get%0A%20%20%20%20%24val1%20%3D%20ConvertFrom-Json%20%24resp1.Content%0A%0A%20%20%20%20foreach%20(%24ard%20in%20%24val1.Value)%20%7B%0A%20%20%20%20%20%20%20%20%24iid%20%3D%20%24ard.id%0A%20%20%20%20%20%20%20%20%24start%20%3D%20%24ard.startDateTime%0A%20%20%20%20%20%20%20%20%24end%20%3D%20%24ard.endDateTime%0A%20%20%20%20%20%20%20%20%24status%20%3D%20%24ard.status%0A%0A%20%20%20%20%20%20%20%20Write-Host%20%22access%20review%20instance%20%24start%20%24end%20%24status%22%0A%20%20%20%20%20%20%20%20if%20(%24status%20-ne%20%22NotStarted%22)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20Get-GraphExampleAccessReviewDecisions%20%24authHeaders%20%24iid%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20Write-Host%20%22%22%0A%7D%0A%0A%0Afunction%20Get-GraphExampleAccessReviews(%24authHeaders%2C%24bftid)%0A%7B%0A%20%20%20%20%24uri1%20%3D%20'https%3A%2F%2Fgraph.microsoft.com%2Fbeta%2FaccessReviews%3F%24filter%3DbusinessFlowTemplateId%2520eq%2520'%20%2B%20%22'%22%20%2B%20%24bftid%20%20%2B%20%22'%22%0A%20%20%20%20Write-Host%20%22GET%20%24uri1%22%0A%20%20%20%20%24resp1%20%3D%20Invoke-WebRequest%20-UseBasicParsing%20-headers%20%24authHeaders%20-Uri%20%24uri1%20-Method%20Get%0A%20%20%20%20%24val1%20%3D%20ConvertFrom-Json%20%24resp1.Content%0A%0A%20%20%20%20foreach%20(%24ar%20in%20%24val1.Value)%20%7B%0A%20%20%20%20%20%20%20%20%24id%20%3D%20%24ar.id%0A%20%20%20%20%20%20%20%20%24displayname%20%3D%20'%22'%20%2B%20%24ar.displayName%20%2B%20'%22'%0A%20%20%20%20%20%20%20%20%24startDateTime%20%3D%20%24ar.startDateTime%0A%20%20%20%20%20%20%20%20%24status%20%3D%20%24ar.status%0A%0A%20%20%20%20%20%20%20%20Write-Host%20%22access%20review%20%24id%20%24displayName%20%24startDateTime%20%24status%22%0A%0A%20%20%20%20%20%20%20%20Get-GraphExampleAccessReviewDecisions%20%24authHeaders%20%24id%0A%0A%20%20%20%20%20%20%20%20Get-GraphExampleAccessReviewInstances%20%24authHeaders%20%24id%0A%20%20%20%20%7D%0A%20%20%20%0A%20%20%20%20%0A%0A%7D%0A%0Afunction%20Get-GraphExampleBusinessFlowTemplates(%24authHeaders)%20%7B%0A%20%20%20%20%24uri1%20%3D%20%22https%3A%2F%2Fgraph.microsoft.com%2Fbeta%2FbusinessFlowTemplates%22%0A%20%20%20%20Write-Host%20%22GET%20%24uri1%22%0A%20%20%20%20%24resp1%20%3D%20Invoke-WebRequest%20-UseBasicParsing%20-headers%20%24authHeaders%20-Uri%20%24uri1%20-Method%20Get%0A%20%20%20%20%24val1%20%3D%20ConvertFrom-Json%20%24resp1.Content%0A%0A%20%20%20%0A%20%20%20%20foreach%20(%24bft%20in%20%24val1.Value)%20%7B%0A%20%20%20%20%20%20%20%20%24id%20%3D%20%24bft.id%0A%20%20%20%20%20%20%20%20Write-Host%20%22business%20flow%20template%20%24id%22%0A%0A%20%20%20%20%20%20%20%20Get-GraphExampleAccessReviews%20%24authHeaders%20%24id%0A%20%20%20%20%20%20%20%20Write-Host%20%22%22%0A%0A%20%20%20%20%7D%0A%7D%0A%0A%24authHeaders%20%3D%20Get-GraphExampleAuthToken%20-User%20%24User%20-ClientId%20%24ClientId%0A%0A%0AGet-GraphExamplePrograms%20%24authHeaders%0A%0AGet-GraphExampleBusinessFlowTemplates%20%24authHeaders%0A%0A%0A%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-236096%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAccess%20Management%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20AD%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
Mark Wahl
Microsoft

The Azure AD access reviews feature now has an API in the Microsoft Graph beta endpoint.  The list of API methods is at https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/accessreviews_root.  While we are in progress of adding access reviews to Azure AD PowerShell and examples of using access reviews from other development platforms to our documentation, the following code sample may be of interest.

Azure AD access reviews data model

The Azure AD access reviews feature adds the following resource types:

  • accessReview: represents an access review.  This can be a one-time review, a recurring review series, or an instance of a recurring review.
  • businessFlowTemplate: the business flow template determines the type resource on which an access review is to be performed. The identifier of a template, such as to review guest members of a group, is supplied by the caller when creating an access review. (The business flow template objects are read only, they are automatically generated when the global administrator onboards the tenant to use the access reviews feature. No additional business flow templates can be created.)
  • program: represents an Azure AD access review program. A program is a container, holding program controls. A tenant can have one or more programs.  Each control links an access review to a program, to make it easier to locate related access reviews.  Each tenant that has onboarded Azure AD access reviews has one program, `Default program`.  A global administrator can create additional programs, for example to represent compliance initiatives.
  • programControl: represents a control, which links an access review to a particular program.
  • programControlType: the program control type is used when associating a control to a program, to indicate the type of access review the control is for. (The program control type objects are read only, they are automatically generated when the global administrator onboards the tenant to use the access reviews feature.  No additional program control types can be created.)

Understanding authorization requirements

The Azure AD access reviews API performs three checks:

  • First, has the tenant onboarded to the feature – Azure AD access reviews or, in the case of access reviews of Azure AD roles, Azure AD PIM. Both of these features are included in Azure AD Premium P2, and require the administrator to have used the features at least once in order to permit the APIs to be called. If you have not already used Azure AD access reviews, the section “Enable Azure AD access reviews in your tenant” below onboards the Azure AD access reviews feature so you can try out the APIs.
  • Second, does the application have the necessary permissions. The permissions available for these APIs are:

    • AccessReview.Read.All: read access reviews
    • AccessReview.ReadWrite.All: read, create, update and delete access reviews
    • ProgramControl.Read.All: read programs and controls
    • ProgramControl.ReadWrite.All: read, create, update and delete programs and controls

If you do not already have those permissions on an application, the section “Register an Azure AD application which can call the access reviews Graph API” below creates a new application and assigns it read permissions.  (You can change the scenario to assign it read and write permission).

  • Third, does the user have the necessary permissions.  This is determined by the calling user’s directory role:

 

Target Resource

Desired Operation

Required directory role of the user, in addition to the application permission

Access review of an Azure AD role

Read

Global Administrator,
Security Administrator,
Security Reader or
Privileged Role Administrator

Create, Update or Delete

Global Administrator or
Privileged Role Administrator

Access review of a group or app

Read

Global Administrator,
Security Administrator,
Security Reader or
User Administrator

Create, Update or Delete

Global Administrator or
User Administrator

Programs or controls

Read

Global Administrator,
Security Administrator,
Security Reader or
User Administrator

Create, Update or Delete

Global Administrator or
User Administrator

 

 

Enable Azure AD access reviews in your tenant

This example assumes you have already onboarded Azure AD access reviews in your tenant directory.  If you have already done so, then skip to the next section “Register an Azure AD application which has permissions to call the access reviews API in Graph”.  Otherwise, continue with these steps to ensure the feature is onboarded so the APIs will return some data.

  1. Log into the Azure portal as a global administrator.
  2. Ensure that your organization has Azure AD Premium P2 or EMS E5 subscription active. If not, click on https://portal.azure.com/#blade/Microsoft_AAD_IAM/TryBuyProductBlade and activate a trial of Enterprise Mobility + Security E5. Otherwise, if your organization has an active subscription, continue at the next step.
  3. Navigate to the Azure AD extension, and click on “Access reviews” on the right hand side under “Other capabilities”.

    3other.png

  4. If you have not already onboarded Azure AD access reviews in your organization, onboard it now.
  5. Click on “Programs” and ensure there is at least one program listed.  At this point you can create additional access reviews if you wish.

  

Register an Azure AD application which has permissions to call the access reviews API in Graph

The Graph authorization model requires that an application must be consented by a user or administrator prior to accessing an organization’s data.  

  1. Log into the Azure portal as a global administrator.
  2. Navigate to the Azure AD extension, and click on “App registrations” in the MANAGE section, to land at the page https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredApps
  3. Click on “New application registration” button at the top of the page.
  4. Provide a name for the application that is different from any other application in your tenant’s directory (e.g., “graphsample”), change the Application type to Native, and provide the following as the Redirect URI:

urn:ietf:wg:oauth:2.0:oob

 

  1. Click “Create”.
  2. When the application is registered, copy the Application ID value, and save the value for later.
  3. Click on Settings, then click on “Required permissions”.
  4. Click on “Add”. Click on “Select an API”, click on “Microsoft Graph”, and then click “Select”.
  5. Azure AD access reviews uses the following delegated permissions: Read all access reviews that use can access, Manage all access reviews that user can access, Read all programs that user can access, and Manage all programs that user can access. This example application requires only the permissions:

    Read all access reviews that user can access
    Read all programs that user can access

    Put a checkbox by those two permissions, and click “Select”.


    14delegated.png

     

    Click “Done”.

(Sample only) Ensure PowerShell and the ADAL libraries are on your computer

The Microsoft Graph requires the application calling it to have an access token.

In this example, the sample code to use the API will leverage the ADAL library which is automatically installed when using Azure AD PowerShell cmdlets.

  1. Ensure that you have PowerShell 3.0 or later, and .NET Framework 4.5 installed on your computer.
  2. Ensure that you have either the Azure AD PowerShell v2 General Availability or Preview modules installed on your computer. If not, more information on how to install them is at https://docs.microsoft.com/en-us/powershell/azure/active-directory/install-adv2?view=azureadps-2.0. Try using Connect-AzureAD to ensure that you can authenticate to Azure AD as a global administrator.

Retrieving the token and calling the API

 

  1. Create a file named “access-reviews-example1.ps1” whose context in the sample PowerShell from the end of this post.
  2. Start PowerShell.
  3. Change to the directory where the access-reviews-example1.ps1 script is located.
  4. Invoke the script, providing on the command line -User with the User principal name (UPN) of a global administrator, and -ClientId with the application ID value from earlier.

    For example,

    .\access-reviews-example1.ps1 -User ga@contoso.onmicrosoft.com
    -ClientId 280d7b83-8d0a-4ee7-8f1a-064ec36d1fa1
  5. When the script is run for the first time in a PowerShell session, you will be asked to authenticate.  For the purposes of this example, ensure that you sign in as a global administrator.
  6. After authenticating, the first time the script is run for a particular application, you will be prompted to consent the application use of permissions.consent.png

     

  1. Once consented, the script will use the token to call Microsoft Graph and retrieve programs, controls, business flow templates and access reviews, and write a summary of them to the PowerShell window.
  2. Note that the authorization is only applicable to the global administrator who consented to the application, and only for that tenant. If other users in the organization or in other applications also wish to use the application, additional steps are required for admin consent.  See the article https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-devhowto-multi-tena... for more information on admin consent in applications.

 

 

Sample (PowerShell)

# Example for using Azure AD access reviews in Microsoft Graph
#
# This material is provided "AS-IS" and has no warranty.
# 
# Last updated August 22, 2018
#
# This example is adapted from the documentation example located at 
# https://docs.microsoft.com/en-us/intune/intune-graph-apis
#
#

Param(
    [Parameter(Mandatory=$true)][string]$User,

    [Parameter(Mandatory=$true)][string]$ClientId
)


# from Intune graph API samples

function Get-GraphExampleAuthToken {
    [cmdletbinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        $User,

        [Parameter(Mandatory = $true)]
        $ClientId,

        [Parameter()]
        $TenantDomain
    )

    $userUpn = New-Object "System.Net.Mail.MailAddress" -ArgumentList $User
    $tenant = $userUpn.Host

    if ($TenantDomain -ne $null) {
        $tenant = $TenantDomain
    }

    Write-Verbose "Checking for AzureAD module..."

    $AadModule = Get-Module -Name "AzureAD" -ListAvailable
    if ($AadModule -eq $null) {
        Write-Host "AzureAD PowerShell module not found, looking for AzureADPreview"
        $AadModule = Get-Module -Name "AzureADPreview" -ListAvailable
    }

    if ($AadModule -eq $null) {
        write-host
        write-host "AzureAD Powershell module not installed..." -f Red
        write-host "Install by running 'Install-Module AzureAD' or 'Install-Module AzureADPreview' from an elevated PowerShell prompt" -f Yellow
        write-host "Script can't continue..." -f Red
        write-host
        exit
    }

    # Getting path to ActiveDirectory Assemblies
    # If the module count is greater than 1 find the latest version

    if ($AadModule.count -gt 1) {
        $Latest_Version = ($AadModule | select version | Sort-Object)[-1]
        $aadModule = $AadModule | ? { $_.version -eq $Latest_Version.version }
        $adal = Join-Path $AadModule.ModuleBase "Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
        $adalforms = Join-Path $AadModule.ModuleBase "Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll"
    }

    else {
        $adal = Join-Path $AadModule.ModuleBase "Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
        $adalforms = Join-Path $AadModule.ModuleBase "Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll"
    }

    [System.Reflection.Assembly]::LoadFrom($adal) | Out-Null
    [System.Reflection.Assembly]::LoadFrom($adalforms) | Out-Null

  
    $redirectUri = "urn:ietf:wg:oauth:2.0:oob"
    $resourceAppIdURI = "https://graph.microsoft.com"

    $authority = "https://login.microsoftonline.com/$Tenant"

    try {
        $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority
        # https://msdn.microsoft.com/library/azure/microsoft.identitymodel.clients.activedirectory.promptbehavior.aspx
        # Change the prompt behaviour to force credentials each time: Auto, Always, Never, RefreshSession
        $platformParameters = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformParameters" -ArgumentList "Auto"
        $userId = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.UserIdentifier" -ArgumentList ($User, "OptionalDisplayableId")
        $authResult = $authContext.AcquireTokenAsync($resourceAppIdURI, $ClientId, $redirectUri, $platformParameters, $userId).Result
        # If the accesstoken is valid then create the authentication header
        if ($authResult.AccessToken) {
            # Creating header for Authorization token
            $authHeader = @{
                'Content-Type' = 'application/json'
                'Authorization' = "Bearer " + $authResult.AccessToken
                'ExpiresOn' = $authResult.ExpiresOn
            }
            return $authHeader
        }
        else {
            Write-Host
            Write-Host "Authorization Access Token is null, please re-run authentication..." -ForegroundColor Red
            Write-Host
            break
        }
    }
    catch {
        write-host $_.Exception.Message -f Red
        write-host $_.Exception.ItemName -f Red
        write-host
        break
    }   
}

# start of access review specific example

function Get-GraphExampleProgramControls($authHeaders,$programId)
{
    $uri1 = "https://graph.microsoft.com/beta/programs('" + $programId + "')/controls"
    Write-Host "GET $uri1"

    $resp1 = Invoke-WebRequest -UseBasicParsing -headers $authHeaders -Uri $uri1 -Method Get
    $val1 = ConvertFrom-Json $resp1.Content

   
    foreach ($c in $val1.Value) {
        $cid = $c.controlId
        $displayname = '"' + $c.displayName + '"'
        Write-Host "control $cid $displayname"
    }

}

function Get-GraphExamplePrograms($authHeaders) {
    $uri1 = "https://graph.microsoft.com/beta/programs"
    Write-Host "GET $uri1"

    $resp1 = Invoke-WebRequest -UseBasicParsing -headers $authHeaders -Uri $uri1 -Method Get
    $val1 = ConvertFrom-Json $resp1.Content

   
    foreach ($program in $val1.Value) {
        $id = $program.id
        $displayname = '"' + $program.displayName + '"'
        Write-Host "program $id $displayName"

        Get-GraphExampleProgramControls $authHeaders $id
        Write-Host ""
    }

}

function Get-GraphExampleAccessReviewDecisions($authHeaders,$arid)
{
    $uri1 = 'https://graph.microsoft.com/beta/accessReviews(' + "'" + $arid  + "')/decisions"
    Write-Host "GET $uri1"
    $resp1 = Invoke-WebRequest -UseBasicParsing -headers $authHeaders -Uri $uri1 -Method Get
    $val1 = ConvertFrom-Json $resp1.Content

    foreach ($ard in $val1.Value) {
        $rr = $ard.reviewResult
        $upn = $ard.userPrincipalName

        Write-Host "access review decision $upn $rr"
    }
    Write-Host ""
}

function Get-GraphExampleAccessReviewInstances($authHeaders,$arid)
{
    $uri1 = 'https://graph.microsoft.com/beta/accessReviews(' + "'" + $arid  + "')/instances"
    Write-Host "GET $uri1"
    $resp1 = Invoke-WebRequest -UseBasicParsing -headers $authHeaders -Uri $uri1 -Method Get
    $val1 = ConvertFrom-Json $resp1.Content

    foreach ($ard in $val1.Value) {
        $iid = $ard.id
        $start = $ard.startDateTime
        $end = $ard.endDateTime
        $status = $ard.status

        Write-Host "access review instance $start $end $status"
        if ($status -ne "NotStarted") {
            Get-GraphExampleAccessReviewDecisions $authHeaders $iid
        }
    }
    Write-Host ""
}


function Get-GraphExampleAccessReviews($authHeaders,$bftid)
{
    $uri1 = 'https://graph.microsoft.com/beta/accessReviews?$filter=businessFlowTemplateId%20eq%20' + "'" + $bftid  + "'"
    Write-Host "GET $uri1"
    $resp1 = Invoke-WebRequest -UseBasicParsing -headers $authHeaders -Uri $uri1 -Method Get
    $val1 = ConvertFrom-Json $resp1.Content

    foreach ($ar in $val1.Value) {
        $id = $ar.id
        $displayname = '"' + $ar.displayName + '"'
        $startDateTime = $ar.startDateTime
        $status = $ar.status

        Write-Host "access review $id $displayName $startDateTime $status"

        Get-GraphExampleAccessReviewDecisions $authHeaders $id

        Get-GraphExampleAccessReviewInstances $authHeaders $id
    }
   
    

}

function Get-GraphExampleBusinessFlowTemplates($authHeaders) {
    $uri1 = "https://graph.microsoft.com/beta/businessFlowTemplates"
    Write-Host "GET $uri1"
    $resp1 = Invoke-WebRequest -UseBasicParsing -headers $authHeaders -Uri $uri1 -Method Get
    $val1 = ConvertFrom-Json $resp1.Content

   
    foreach ($bft in $val1.Value) {
        $id = $bft.id
        Write-Host "business flow template $id"

        Get-GraphExampleAccessReviews $authHeaders $id
        Write-Host ""

    }
}

$authHeaders = Get-GraphExampleAuthToken -User $User -ClientId $ClientId


Get-GraphExamplePrograms $authHeaders

Get-GraphExampleBusinessFlowTemplates $authHeaders


 

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
48 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
30 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies