Iframe Microsoft Graph and Sharepoint

Mariano Lorelli 0 Reputation points
2024-01-23T16:49:44.17+00:00

I have a question regarding Microsoft Graph and SharePoint. Is it possible to generate a link using the API to view a SharePoint document in my application within an iframe without prompting for a Microsoft username and password? The idea would be to achieve this using a token or something similar. If not, how could I go about displaying a SharePoint document in my app? The front-end is built in Angular, and the back-end is in C#. Where should it go? I need to show in my app a document from sharepoint

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,018 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,184 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,288 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.
3,278 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
23,182 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sourabh Gupta 800 Reputation points Microsoft Vendor
    2024-01-27T12:49:19.7833333+00:00

    Hi @Mariano Lorelli Thanks for reaching out. You can use following code in C# to generate link for a drive item.

    // Code snippets are only available for the latest version. Current version is 5.x
    
    // Dependencies
    using Microsoft.Graph.Drives.Item.Items.Item.CreateLink;
    
    var requestBody = new CreateLinkPostRequestBody
    {
    	Type = "view",
    	Password = "ThisIsMyPrivatePassword",
    	Scope = "anonymous",
    	RetainInheritedPermissions = false,
    };
    
    // To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
    var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].CreateLink.PostAsync(requestBody);
    

    The above example requests a sharing link to be created for the DriveItem specified by {itemId} in the user's OneDrive. The sharing link is configured to be read-only and usable by anyone with the link. All existing permissions are removed when sharing for the first time if retainInheritedPermissions is false. For an item on sharepoint site you can use the following end point /sites/{siteId}/drive/items/{itemId}/createLink

    var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].CreateLink.PostAsync(null);
    

    For more information related to generating links with different access level refer to following documentation from Microsoft. https://learn.microsoft.com/en-us/graph/api/driveitem-createlink?view=graph-rest-1.0&tabs=csharp If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.