Does MSAL auth flow with Angular give access to Microsoft Graph API only?

Anu Virtanen 46 Reputation points
2021-12-23T09:18:27.977+00:00

Hello,

I followed this tutorial to develop a webapp that can make API calls. My need is not for MS Graph but for Microsot Azure Devops Rest api.
https://learn.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-angular-auth-code

Login and logout to Azure AD in the webapp works as it should (as shown in the tutorial). Api calls to Microsoft Graph work like a charm. When I attempt to implement API call to Microsoft Azure Devops Rest Api, I get a response 203.
![160052-image.png]2 160061-image.png

I have granted permissions in Azure portal for the webapp to access Microsoft Azure Devops Rest Api with scope user_impersonation 160076-image.png 160018-image.png
and mapped the resource in app.module.ts 160073-image.png

Authentication part I have configured as instructed in the tutorial:
160064-image.png

When I make the API call to Azure Devops Rest Api using python script (using access token I created in Azure), it works. I am also able to navigate to the url where I want to make API call to, and access data. 160016-image.png But in this webapp, using auth flow and MSAL as instructed in the tutorial, it returns response 203.

My primary question is: Following the instructions in this tutorial, is it only possible to access MS Graph API and not Azure Devops Rest Api?
My secondary question is: How can I then successfully send API calls to Azure Devops Rest Api in an Angular SPA?

Thanks a lot,
Anu

Community Center | Not monitored
0 comments No comments
{count} votes

Accepted answer
  1. JamesTran-MSFT 36,911 Reputation points Microsoft Employee Moderator
    2021-12-28T18:19:55.72+00:00

    @Anu Virtanen
    Thank you for your post and I apologize for the delayed response!

    I'm not too familiar with DevOps but based off the tutorial you followed - Sign in users and call the Microsoft Graph API from an Angular single-page application (SPA) using auth code flow, it looks like it's used specifically for signing in users and calling the Microsoft Graph API using the authorization code flow with PKCE. The SPA within the tutorial uses the Microsoft Authentication Library (MSAL).

    To successfully authenticate to and use the Azure DevOps Services REST API, it looks like you'll need to use the Active Directory authentication library (ADAL), OAuth, Device Profile, or VSS Web Extension SDK. For more info - Authenticate.

    Since Azure DevOps is currently not supported here on Q&A, I'd recommend reaching out to our DevOps experts via the following forums.

    Azure DevOps Developer Community
    Azure DevOps Server (TFS) Community
    Azure DevOps Tech Community

    I hope this helps!

    If you have any other questions, please let me know.
    Thank you for your time and patience throughout this issue.

    ----------

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Anu Virtanen 46 Reputation points
    2022-01-07T12:22:18.167+00:00

    Thanks @JamesTran-MSFT for the info. I finally got it to work! :D

    I followed the instructions you linked here https://github.com/microsoft/azure-devops-auth-samples/tree/master/JavascriptWebAppSample
    and even though that implementation was not suitable for my purpose at this time, in there I saw a value in config.json that I had not seen in any other instructions this far
    ![163147-image.png]2

    And when I put that in my app.module.ts as scope instead of the value that I had read I should put 163148-image.png
    it started working. So thanks to you linking the other sample, I found the valid scope value which seems to have been the problem. Thank you very much!

    1 person found this answer helpful.

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.