{"id":4187,"date":"2024-07-19T13:36:53","date_gmt":"2024-07-19T12:36:53","guid":{"rendered":"https:\/\/www.lieben.nu\/liebensraum\/?p=4187"},"modified":"2024-07-19T13:36:53","modified_gmt":"2024-07-19T12:36:53","slug":"sharepoint-online-and-azure-datafactory-using-managed-identity","status":"publish","type":"post","link":"https:\/\/lieben.nu\/liebensraum\/2024\/07\/sharepoint-online-and-azure-datafactory-using-managed-identity\/","title":{"rendered":"Sharepoint Online and Azure Datafactory using Managed Identity"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Let&#8217;s face it, Microsoft&#8217;s documentation on using Sharepoint as a data source (or sink) in ADF is <a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/data-factory\/connector-sharepoint-online-list?tabs=data-factory\" data-type=\"link\" data-id=\"https:\/\/learn.microsoft.com\/en-us\/azure\/data-factory\/connector-sharepoint-online-list?tabs=data-factory\">pretty bad.<\/a> And it doesn&#8217;t even describe how to use the Managed Identity of ADF, who still wants to register separate app credentials? Noooooo you don&#8217;t.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So here&#8217;s an example how to use Managed Identity to read a json file from a given SpO site, using minimal permissions given to ADF.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Enable MI in datafactory, I&#8217;m assuming you know how to do this.<\/li>\n\n\n\n<li>Give ADF Sites.Selected Graph permissions, e.g. like this:<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\nParam(\n    &#x5B;Parameter(Mandatory=$true)]&#x5B;String]$displayName=\"{NAMEOFADFINSTANCE}\",\n    &#x5B;Parameter(Mandatory=$true)]&#x5B;String]$role=\"Sites.Selected\"\n)\nConnect-AzureAD \n$Msi = (Get-AzureADServicePrincipal -Filter \"displayName eq '$displayName'\")\nStart-Sleep -Seconds 10\n$baseSPN = Get-AzureADServicePrincipal -Filter \"appId eq '00000003-0000-0000-c000-000000000000'\"\n$AppRole = $baseSPN.AppRoles | Where-Object {$_.Value -eq $role -and $_.AllowedMemberTypes -contains \"Application\"}\nNew-AzureAdServiceAppRoleAssignment -ObjectId $Msi.ObjectId -PrincipalId $Msi.ObjectId -ResourceId $baseSPN.ObjectId -Id $AppRole.Id\n$Msi.AppId\n<\/pre><\/div>\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>Go to https:\/\/yourtenant.sharepoint.com\/sites\/yoursite\/_api\/site\/id and copy the Edm Guid:<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/www.lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1307\" height=\"163\" src=\"https:\/\/www.lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image.png\" alt=\"get sharepoint site ID \/ guid\" class=\"wp-image-4190\" style=\"width:826px;height:auto\" srcset=\"https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image.png 1307w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-300x37.png 300w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-1024x128.png 1024w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-768x96.png 768w\" sizes=\"auto, (max-width: 1307px) 100vw, 1307px\" \/><\/a><\/figure>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li>Go to https:\/\/developer.microsoft.com\/en-us\/graph\/graph-explorer. Log in at the top right using a user with sufficient permissions (Sites.FullControl.All), set the mode to POST, add the EDM guid in the URL and create the request body as follows (the id in the body can be found back in step 2, $Msi.AppId)<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/www.lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1420\" height=\"708\" src=\"https:\/\/www.lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-1.png\" alt=\"authorize managed identity on sharepoint site\" class=\"wp-image-4191\" style=\"width:800px;height:auto\" srcset=\"https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-1.png 1420w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-1-300x150.png 300w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-1-1024x511.png 1024w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-1-768x383.png 768w\" sizes=\"auto, (max-width: 1420px) 100vw, 1420px\" \/><\/a><\/figure>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li>Create a REST linked service in ADF with Managed Identity auth:<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/www.lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"621\" height=\"834\" src=\"https:\/\/www.lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-2.png\" alt=\"create graph rest linked identity\" class=\"wp-image-4192\" style=\"width:425px;height:auto\" srcset=\"https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-2.png 621w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-2-223x300.png 223w\" sizes=\"auto, (max-width: 621px) 100vw, 621px\" \/><\/a><\/figure>\n\n\n\n<ol start=\"6\" class=\"wp-block-list\">\n<li>Create data source in ADF of type REST<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-3.png\"><img loading=\"lazy\" decoding=\"async\" width=\"934\" height=\"618\" src=\"https:\/\/www.lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-3.png\" alt=\"\" class=\"wp-image-4193\" srcset=\"https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-3.png 934w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-3-300x199.png 300w, https:\/\/lieben.nu\/liebensraum\/wp-content\/uploads\/2024\/07\/image-3-768x508.png 768w\" sizes=\"auto, (max-width: 934px) 100vw, 934px\" \/><\/a><\/figure>\n\n\n\n<ol start=\"7\" class=\"wp-block-list\">\n<li>Replace the &#8220;uri&#8221; with the direct url of the file you want to read (or use an alternative method). Example uri:<br><a href=\"https:\/\/graph.microsoft.com\/v1.0\/sites\/de624b7d-dd15-4701-8c12-94e6cc3386a9\/drive\/root:\/General\/Input_files\/test.json:\/content\">https:\/\/graph.microsoft.com\/v1.0\/sites\/ee614b6d-de15-4101-1c12-14e4cd3186a9\/drive\/root:\/General\/Input_files\/test.json:\/content<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s face it, Microsoft&#8217;s documentation on using Sharepoint as a data source (or sink) in ADF is pretty bad. And it doesn&#8217;t even describe how to use the Managed Identity of ADF, who still wants to register separate app credentials? Noooooo you don&#8217;t. So here&#8217;s an example how to use Managed Identity to read a &hellip; <a href=\"https:\/\/lieben.nu\/liebensraum\/2024\/07\/sharepoint-online-and-azure-datafactory-using-managed-identity\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Sharepoint Online and Azure Datafactory using Managed Identity<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":4194,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[10,13,21,44],"tags":[],"class_list":["post-4187","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-factory","category-entraid","category-identity","category-sharepoint-online"],"_links":{"self":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/4187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/comments?post=4187"}],"version-history":[{"count":0,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/4187\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/media\/4194"}],"wp:attachment":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/media?parent=4187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/categories?post=4187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/tags?post=4187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}