How to get a user identity/access token in Sharepoint to pass to iframe?

Eugen 1 Reputation point


We are embedding in a SharePoint page:

We managed to include it and display it.

The app at has it's own authentication implemented.

We want to allow users authenticated at the sharepoint page to this app.

What is the best way to achieve this integration ?

How should we convert the identity of Sharepoint users to our users?

My guess would be to use JS and fetch a user identity token then pass this token to a service / our service and validate the token on the app side. By token, in this context I understand a signed JWT token.

Initially asked .



A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,240 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 33,486 Reputation points Microsoft Vendor

    Hi @Eugen
    You need to pass TenantID, Client ID, Client Secret and resource details to get the access token. Please refer to following code

        type: 'POST',  
        crossDomain: true,  
        url: '<tenantID>/tokens/OAuth/2',  
        headers: {  
            "content-type": "application/x-www-form-urlencoded"  
        data: {  
            "grant_type": "client_credentials",  
            "client_id": "<ClientID>@<TenantID>",  
            "client_secret": "<ClientSecret>",  
            "resource": "00000003-0000-0ff1-ce00-000000000000/<sitename><TenantID>"  
        success: function(data) {  
            //data.token_type returns "Bearer"  
            //data.access_token returns < AccessToken >  
            var at = data.token_type + " " + data.access_token;  
          //caal the REST API with the at variable in header  
        error: function(data, errorThrown, status) {  

    Then you can use getElementbyId to pass values to iFrame like this

    <script type="text/javascript">  
        var params = "xxxxxxxxxxxxxxxxxxxxx";  
        document.getElementById("myIframe").src = '' + params;  
    <iframe id="myIframe" src="" width="80%"></iframe>  

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.