Last active
October 1, 2024 17:31
-
-
Save bgavrilMS/2467f863aa462333990a42d4b6a74fe9 to your computer and use it in GitHub Desktop.
MISE basic usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//See below for a replacement of "ClientSecretCredential". | |
//For a full sample showcasing "ManagedIdentityCredential" see https://github.com/Azure-Samples/active-directory-dotnetcore-daemon-v2/tree/master/6-Call-OwnApi-ManagedIdentity | |
// Config json (can be programatic too) | |
/* | |
{ | |
"AzureAd": { | |
"Instance": "https://login.microsoftonline.com/", | |
"TenantId": "[Enter here the tenantID or domain name for your Azure AD tenant]", | |
"ClientId": "[Enter here the ClientId for your application]", | |
"ClientCredentials": [ | |
{ | |
"SourceType": "ClientSecret", | |
"ClientSecret": "[Enter here a client secret for your application]" | |
} | |
] | |
}, | |
"MyWebApi": { | |
"BaseUrl": "https://localhost:44372/", | |
"RelativePath": "api/TodoList", | |
"RequestAppToken": true, | |
"Scopes": ["[Enter here the scopes for your web API]"] // . E.g. 'api://<API_APPLICATION_ID>/.default' | |
} | |
} | |
*/ | |
// Token Acquisition API - gets auth headrs, similar to MSAL | |
ITokenAcquirer acquirer = sp.GetRequiredService<ITokenAcquirer>(); | |
AcquireTokenResult result = await acquirer.GetTokenForAppAsync("https://graph.microsoft.com/.default"); | |
// Downstream API - uses TokenAcquisition to make HTTP calls to resources, handles CAE etc. | |
IDownstreamApi downstreamApi = sp.GetRequiredService<IDownstreamApi>(); | |
HttpResponseMessage apiResult = await downstreamApi.CallApiForAppAsync("MyWebApi"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment