Quantcast
Channel: Azure Active Directory forum
Viewing all articles
Browse latest Browse all 16000

request.isauthenticated always false in webforms - Azure Ad authentication

$
0
0

Hi Team, 

request.isauthenticated always false in webforms application that using AZURE AD even after successful redirection from azure ad login. i wonder what causing the issue. by the way i have not deployed my web app to azure yet. testing the app in local by giving redirect uri as localhost:xxxx\home

The same code working fine in MVC.

In webforms i have login.aspx --> AZURE AD --> redirect back to homepage.

when i try to check request.isauthentication in home page it says false. all required config parameters in web.config

User.Identity is empty. although when i am debugging i can see the token that returning from AZURE and user details. however these are not attaching to the current httpcontext

                                                                       

<add key="webpages:Version" value="3.0.0.0" />

    <add key="webpages

:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <!--Application keys for AZURE AD -->
    <add key="ida:AADInstance" value="https://login.microsoftonline.com/{0}" />
    <add key="ida:PostLogoutRedirectUri" value="http://azureadwebapplication.azurewebsites.net/" />
    <add key="ida:GraphApiVersion" value="1.6" />
    <add key="ida:GraphUrl" value="https://graph.windows.net" />
    <add key="ida:CertName" value="" />
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <!-- Modify these values-->
    <!--cloud app     -->
    <add key="ida:ClientId" value="" />
    <add key="ida:AppKey" value="" />
    <add key="ida:Tenant" value=".onmicrosoft.com" />
    <add key="ida:TenantId" value="" /> return new OpenIdConnectAuthenticationOptions
                {
                    ClientId = Utils.Constants.ClientId,
                    Authority = Authority,
                    PostLogoutRedirectUri = Utils.Constants.PostLogoutRedirectUri,
                    RedirectUri = Utils.Constants.PostLogoutRedirectUri,

                    Notifications = new OpenIdConnectAuthenticationNotifications()
                    {
                        //
                        // If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away.
                        //
                        AuthorizationCodeReceived = async (context) =>
                        {
                            var code = context.Code;
                            // Create a Client Credential Using an Application Key
                            ClientCredential credential = new ClientCredential(Utils.Constants.ClientId, Utils.Constants.AppKey);
                            string userObjectID = context.AuthenticationTicket.Identity.FindFirst(
                                "http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
                            AuthenticationContext authContext = new AuthenticationContext(Authority, new NaiveSessionCache(userObjectID));
                            AuthenticationResult result = await authContext.AcquireTokenByAuthorizationCodeAsync(
                                code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, Utils.Constants.GraphResourceId);
                            AuthenticationHelper.token = result.AccessToken;


                        }

                    }

I am getting the token and redirecting to my homepage but  request.isauthenticated is false. 

I appreciate your help

thanks

Kalyan


Kalyan



Viewing all articles
Browse latest Browse all 16000

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>