0

Please help me to find out the documentation on how to use java MASL SDK to get access_token for a service principal. I am looking to find the documentation or GIT links which can guide me how to use the MASL library including the code samples.

I have gone through this link but it does not help me much : https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows

And, I am not expecting code samples to be shared here. I just want to find out where to find such data. I am struggling a lot when it comes to finding the right knowledge with respect to azure learning. What am I missing here? Is there any azure reference link available to find such information at a centralized place?

Onki
  • 1,879
  • 6
  • 38
  • 58

1 Answers1

0

Note that, based on your requirement you can make use of Authorization code Flow if you want the user to sign-in and authenticate and if you want to access API using Application then make use of Client Credential Flow.

I tried to reproduce the same in my environment and got the results like below:

I created an Azure AD Application and added API permission:

enter image description here

For Client-Credential Flow, refer this GitHub blog by siddhijain.

Use the MASL java SDK to authenticate user in azure function developed in java.

Assuming that you want to authenticate user, you can make use of Authorization code Flow to generate access token.

I generated the Authorization code by using below endpoint:

https://login.microsoftonline.com/TenantID/oauth2/v2.0/authorize?
&client_id=ClientID
&response_type=code
&redirect_uri=RedirectUri
&response_mode=query
&scope=https://management.azure.com/user_impersonation
&state=12345

A sign-in screen will appear for authenticating the user:

enter image description here

enter image description here

To generate the access token, I used below parameters:

https://login.microsoftonline.com/TenantID/oauth2/v2.0/token

client_id:ClientID
client_secret:ClientSecret
scope:https://management.azure.com/user_impersonation
grant_type:authorization_code
redirect_uri:RedirectUri
code:code

enter image description here

I am able to call the Function by using above generated access token:

enter image description here

To implement the above in MSAL Java library, refer the below GitHub Blogs:

Microsoft-authentication-library-for-js/msal-node/auth-code AzureAD by derisen

Microsoft-authentication-library-for-js/samples/msal-node AzureAD by rgins16

Rukmini
  • 6,015
  • 2
  • 4
  • 14