c# - Microsoft graph API how to create a bearer msal token -
trying authenticate, application basic console app, (not user) , access token right scopes. manage token without right scopes. i'm not sure if able this, missing?
static async task<string> getmsaltoken()         {             const string clientid = "xxxx234a3-7b9f-42341c-86df-3d2349861";             const string clientsecret = "wx324xxxxxxxxxxxxx";             var scopes = new list<string>() { "https://graph.microsoft.com/.default" };              var clientcredential = new microsoft.identity.client.clientcredential(clientsecret);             var redirecturi = "msalxxxx234a3-7b9f-42341c-86df-3d2349861://auth";              var clientapplication = new microsoft.identity.client.confidentialclientapplication(clientid, redirecturi, clientcredential, null, null);             var authenticationresult = await clientapplication.acquiretokenforclientasync(scopes);              return authenticationresult.accesstoken;         } 
you using client credential authentication using application permissions in azure ad v2.0 endpoint , value passed scope parameter in request should resource identifier (application id uri) of resource want, affixed .default suffix. example ,the microsoft graph , value https://graph.microsoft.com/.default.
with client credential flow , application uses organization's data, not specific user. in such case, "administrator consent" (admin consent) used in azure ad, , consent must done administrator in organization. when use administrator consent, have go https://login.microsoftonline.com/{tenant name}/adminconsent?client_id={application id}&state={some state data}&redirect_uri={redirect uri}using web browser.
after admin consent , acquiring token microsoft graph using client credential flow , if decode access token using online tool , find application permissions listed in roles claim . please confirm have done admin consent application permissions .
here is tutorial using client credentials flow azure ad v2.0 endpoint.
Comments
Post a Comment