locked
Integrate Authentication token with subsequent httprequest / SharePoint ClientContext / Javascript get RRS feed

  • Question

  • User369345748 posted

    I have used the following tutorial 
    https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-v2-aspnet-webapp to authenticate to Azure AD and to retrieve a set of claims about my credential.

    EG
    var userClaims = User.Identity as System.Security.Claims.ClaimsIdentity;
    string accessToken = userClaims?.FindFirst( "access_token")?.Value;

    Please can anyone point me to a tutorial / code that lets me use the userClaims to provide an Authentication token to the following: 

    1 C# >>> http post or get  via WebClient / HttpClient ? request or equivalent 

    2 C# >>> SharePoint Online ClientContext   

    3 Jquery / Javascript / AngularJS Http get / post

    Thank you.   

    PS.If think that this is relevant for this forum, please do advise what forum it should go in.

    Thanks again.

    regards Richard

    Wednesday, April 15, 2020 2:15 PM

All replies

  • User1535942433 posted

    Hi Richard Scannell,

    Accroding to your description,you could get access_token in the context about C# httpclient.

    More details,you could refer to below codes:

    C# httpclient:

    var accessToken = await HttpContext.GetTokenAsync("access_token");
                    var client = new HttpClient();
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                    var content = await client.GetStringAsync("http://localhost:5001/identity");

    AngularJS:

    More details,you could refer to below article:

    https://docs.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-angular

    Best regards,

    Yijing Sun

    Friday, April 17, 2020 1:23 AM