Not able to connect my App after Redirect from okta log in Page

Afte Login to okta page i am getting not found error in redirect url page.
My code in default.aspx(Login page)

    If Not Request.IsAuthenticated Then

        New AuthenticationProperties With
        .RedirectUri = "/"

    End If

I am using OIDC and web form .

This my Startup.cs file

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)
    End Sub

    Public Sub ConfigureAuth(ByVal app As IAppBuilder)
        'New CookieAuthenticationOptions With
        '{.AuthenticationType = "Cookies",
        '                     .CookieManager = New Microsoft.Owin.Host.SystemWeb.SystemWebChunkingCookieManager()
        '        })

        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 {
                    .AuthenticationFailed = Function(context)

                                                If context.Exception.Message.Contains("IDX21323") Then
                                                    Return Task.FromResult(0)
                                                End If
                                                Return Task.FromResult(0)
                                            End Function,
                  .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)
                                               End Function,
                  .RedirectToIdentityProvider = Function(n)

                                                    If n.ProtocolMessage.RequestType = OpenIdConnectRequestType.Logout Then
                                                        Dim idTokenClaim = n.OwinContext.Authentication.User.FindFirst("id_token")

                                                        If idTokenClaim IsNot Nothing Then
                                                            n.ProtocolMessage.IdTokenHint = idTokenClaim.Value
                                                        End If
                                                    End If

                                                    Return Task.CompletedTask
                                                End Function

Do you see the token api call made to the right end point ? Do you see any failures in okta system log ?

1 Like

Getting 500 internal server error in network trace of my browser

Screenshot 2022-12-28 123716

also getting this issues

Solved the issue by changing the token client

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.