Created
September 24, 2020 16:28
-
-
Save cheenamalhotra/8398e61f8c50388382c6dd0e84609720 to your computer and use it in GitHub Desktop.
Test Token Acquire from MSAL library
This file contains 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
using System; | |
using Microsoft.Identity.Client; | |
namespace TestMSAL | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
RunServicePincipalTest(); | |
} | |
private static void RunServicePincipalTest() | |
{ | |
// Format: https://login.windows.net/<tenant-id>/ | |
string authority = ""; | |
string appId = ""; | |
string appSecret = ""; | |
string scope = "https://database.windows.net//.default"; | |
string[] scopes = new string[] { scope }; | |
IConfidentialClientApplication ccApp = ConfidentialClientApplicationBuilder.Create(appId) | |
.WithAuthority(authority) | |
.WithClientSecret(appSecret) | |
.WithClientName("Test Application") | |
.WithClientVersion("1.0") | |
.Build(); | |
AuthenticationResult result = ccApp.AcquireTokenForClient(scopes).ExecuteAsync().Result; | |
Console.WriteLine("Access Token " + result.AccessToken); | |
Console.WriteLine("Expires On " + result.ExpiresOn); | |
} | |
} | |
} |
This file contains 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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>netcoreapp3.1</TargetFramework> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.Identity.Client" Version="4.18.0" /> | |
</ItemGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment