1. Below is app settings to use the
<add key="ida:AADInstance" value="https://login.microsoftonline.com/{0}" />
<add key="ida:Tenant" value="f61023-bd24-4569-812b-56c280afb521" />
<add key="ida:ClientId" value="620f4139-42b5-4132-1234-785f091dss3" />
<add key="ida:ClientSecureKey" value="fsdfv3m23bNNBbfjfbbdddsennmh" />
<add key="ida:RedirectUri" value="620f4139-42b5-4132-1234-785f091dss3" />
2. Below method used to get the access token on behalf of registered Application clietnId and securekey
public async Task<string> Authentication()
{
string accessToken = string.Empty;
try
{
string authorityy = string.Format(CultureInfo.InvariantCulture, CommonService.AADInstance, CommonService.tenantId);
AuthenticationContext authContext = new AuthenticationContext(authorityy);
// //Pass the credential
var clientCredential = new ClientCredential(CommonService.clientId, CommonService.ClientSecureKey);
var result = authContext.AcquireTokenAsync(CommonService.RedirectUri, clientCredential).Result;
//Acquire the token
accessToken = result.AccessToken;
}
catch (Exception ex)
{
string errorString = "Error in UserAuthontication :" + ex.Message.ToString() + "\n" + ex.StackTrace;
Console.WriteLine(errorString);
CommonService.WriteLogg(errorString);
}
return accessToken;
}
No comments:
Post a Comment