We have an existing asp.net empty web application. We need to implement Azure Active Directory Authentication for this websites. I am using below code to Acquire tokens using below code.
protected async void btnLogin_Click(object sender, EventArgs e)
{
//AuthenticationResult result = null;
try
{
string aadInstance = ConfigurationManager.AppSettings["aadInstance"];
string tenant = ConfigurationManager.AppSettings["tenant"];
string authority = string.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
Uri redirectURl = new Uri(ConfigurationManager.AppSettings["redirectURl"]);
string clientID = ConfigurationManager.AppSettings["clientID"];
string resouceID = ConfigurationManager.AppSettings["resouceID"];
AuthenticationContext AuthContext;
AuthContext = new AuthenticationContext(authority);
var obj = await AuthContext.AcquireTokenAsync(resouceID, clientID, redirectURl, new PlatformParameters(PromptBehavior.Auto));
if (obj.AccessToken != null)
{
AddSession(obj.UserInfo.GivenName);
Response.Redirect("Home.aspx", false);
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
This code works fine while debugging, opens Azure login page and we get access token. But when deploying this application on server, azure login page doesn't open and I get following error.
Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
Can someone help me in achieving access tokens from azure active directory using asp.net web form?