<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content
0D54z00007eS6JfCAKOkta Classic EngineAuthenticationAnswered2024-03-05T14:55:11.000Z2022-05-17T15:18:07.000Z2022-05-30T15:15:18.000Z

BrianW.03127 (Customer) asked a question.

Request.IsAuthenticated is always false

I did implemented the OKTA authentication in VB.NET application. It's successfully redirecting to the Okta Site, getting authenticated. But When I check with the Request.IsAuthenticated, its always false. Because of that my application hitting OKTA again and again. Please refer my startup class below

 

<Assembly: OwinStartup(GetType(FacilityRevocationManagement.Startup))>

Namespace FacilityRevocationManagement

  Public Class Startup

    Private ReadOnly _clientId As String = ConfigurationManager.AppSettings("okta:ClientId")

    Private ReadOnly _redirectUri As String = ConfigurationManager.AppSettings("okta:RedirectUri")

    Private ReadOnly _authority As String = ConfigurationManager.AppSettings("okta:OrgUri")

    Private ReadOnly _clientSecret As String = ConfigurationManager.AppSettings("okta:ClientSecret")

 

    Public Sub Configuration(ByVal app As IAppBuilder)

      System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

      IdentityModelEventSource.ShowPII = True

      app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType)

      ConfigureAuth(app)

    End Sub

 

    Public Sub ConfigureAuth(ByVal app As IAppBuilder)

      app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie)

      app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType)

      app.UseCookieAuthentication(New CookieAuthenticationOptions())

      app.UseOpenIdConnectAuthentication(New OpenIdConnectAuthenticationOptions With {

      .ClientId = _clientId,

      .ClientSecret = _clientSecret,

      .Authority = _authority,

      .RedirectUri = _redirectUri,

      .ResponseType = OpenIdConnectResponseType.CodeIdToken,

      .Scope = OpenIdConnectScope.OpenIdProfile,

      .TokenValidationParameters = New TokenValidationParameters With {

        .NameClaimType = "name"

      },

      .Notifications = New OpenIdConnectAuthenticationNotifications With {

      .AuthorizationCodeReceived = Async Function(n)

                       Dim tokenClient = New TokenClient($"{_authority}/v1/token", _clientId, _clientSecret)

                       Dim tokenResponse = Await tokenClient.RequestAuthorizationCodeAsync(n.Code, _redirectUri)

 

                       If tokenResponse.IsError Then

                         Throw New Exception(tokenResponse.[Error])

                       End If

 

                       Dim userInfoClient = New UserInfoClient($"{_authority}/v1/userinfo")

                       Dim userInfoResponse = Await userInfoClient.GetAsync(tokenResponse.AccessToken)

                       Dim claims = New List(Of Claim)(userInfoResponse.Claims) From {

                 New Claim("id_token", tokenResponse.IdentityToken),

                               New Claim("access_token", tokenResponse.AccessToken)

                             }

                       n.AuthenticationTicket.Identity.AddClaims(claims)

                     End Function

        }

      })

    End Sub

  End Class

 

This function used to check whether user authenticated

 

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not IsPostBack Then

      If Not Request.IsAuthenticated Then

        HttpContext.Current.GetOwinContext().Authentication.Challenge(New AuthenticationProperties With {

          .RedirectUri = "/FacilityRevocationManagement/View/Welcome.aspx"

        }, OpenIdConnectAuthenticationDefaults.AuthenticationType)

      End If


  • flaviu.vrinceanu1.5628408972654734E12 (Customer Success Service Delivery)

    Hi @BrianW.03127 (Customer)​,

     

    Thank you for posting on the Okta community page!

     

    I have done some research on my end but unfortunately I couldn't find a specific reason of why Request.IsAuthenticated is always false but could you please check if your local server is running on https and not http?

     

    Additionally, my advice would be to also leverage the Okta Developer forums for this type of questions and take advantage of their expertise.

     

    I hope the above information is useful!

    Expand Post
  • BrianW.03127 (Customer)

    Thanks for your answer and sorry for my late reply. I found the issue from my side. Actually I copied the ORGURI from address bar instead of details in the application. Address bar URL is identical to the ORGURI, but actually not. Once I found that I'm able to get Authenticate as usual.

This question is closed.
Loading
Request.IsAuthenticated is always false