I have a WPF application, it will authenticate with Azure AD and return a Token. While calling the methods Web API, we are passing this token to server machine. In server we need to validate the token is valid or not. Can you please help me for the validation code in server machine
string aadInstance = service.SelectSingleNode("AADInstance").InnerText;
string tenant = service.SelectSingleNode("Tenant").InnerText;
string clientId = service.SelectSingleNode("ClientId").InnerText;
string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
authContext = new AuthenticationContext(authority, new FileCache());
Uri redirectUri = new Uri(service.SelectSingleNode("RedirectUri").InnerText);
string resourceId = service.SelectSingleNode("ResourceId").InnerText;
AuthenticationResult result = null;
try
{
result = await authContext.AcquireTokenSilentAsync(resourceId, clientId);
}
catch (AdalException ex)
{
if (ex.ErrorCode == AdalError.UserInteractionRequired || ex.ErrorCode == AdalError.FailedToAcquireTokenSilently)
{
result = await authContext.AcquireTokenAsync(resourceId, clientId, redirectUri, new PlatformParameters(PromptBehavior.Always));
}
}
tocken = result.AccessToken;