1

I want to generate an access token and embed token of the azure active directory from my web app using javascript. I tried to generate token by calling REST-API using ajax but I faced CORS issue. Then I tried using ADAL and MSAL but nothing work. How can I generate a token in my web app programmatically?

Akshay
  • 85
  • 9

1 Answers1

3

You could use ADAL/MSAL to integrate AAD in javascript. If using the client credentials flow that is not supported in javascript, you will get the CORS error.

There are samples to acquire access token:

unknown
  • 6,778
  • 1
  • 5
  • 14
  • Thaks for your response. These all articles redirect me to the login window. I don't want any popup. I simply want to add code to my web app which generates an access token for me. Is there is any way to do that? – Akshay Dec 23 '20 at 10:52
  • Both implicit grant flow and authorization code flow need to sign the user into your app first. I'm afraid you must do the request from a back-end application with client credentials flow that I mentioned in the reply. Also, the [answer](https://stackoverflow.com/a/52839465/13308381) has explained about it. – unknown Dec 23 '20 at 13:46
  • Thanks for your response Pamela Peng.. By using this implicit flow I stuck on an error. The error is "InteractionRequiredAuthError: AADSTS65001: The user or administrator has not consented to use the application with ID 'xxxxxx' named 'xxxxx powerBI Embed Test1'. Send an interactive authorization request for this user and resource." can you please help me out? – Akshay Dec 27 '20 at 13:18
  • Which example did you follow? If you use ADAL, plz refer to this [issue](https://stackoverflow.com/a/47233008/13308381). – unknown Dec 27 '20 at 13:43
  • I solved it. It is necessary to add mail.read permission in Microsoft graph API. Just login with your admin account and go to app registration then select API permissions and click on add permission – Akshay Dec 27 '20 at 18:33
  • I'm glad to know :) – unknown Dec 28 '20 at 01:12