<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
0D54z000075v8zQCAQOkta Classic EngineAuthenticationAnswered2021-08-03T02:57:20.000Z2021-07-30T06:23:46.000Z2021-08-03T02:57:20.000Z
  • JosephJ.99172 (Customer)

    Hi Tiberiu

    Thanks for your reply. I am sorry, I couldn't sample to use OKTA for ASP.NET in Visual basic code. Can you please send me the sample or the link for it.

    Thanks

    Joseph

  • JosephJ.99172 (Customer)

    Hi Tiberiu

    When I converted the Startup class from C# to VB, I got the following error message:

     

    Severity Code Description Project File Line Suppression State

    Error BC30516 Overload resolution failed because no accessible 'New' accepts this number of arguments. OKTA_DEMO C:\OKTA_DEMO\Startup.vb 42 Active

     

    Severity Code Description Project File Line Suppression State

    Error BC30456 'RequestAuthorizationCodeAsync' is not a member of 'TokenClient'. OKTA_DEMO C:\OKTA_DEMO\Startup.vb 43 Active

     

    Severity Code Description Project File Line Suppression State

    Warning BC42105 Function '<anonymous method>' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used. OKTA_DEMO C:\OKTA_DEMO\Startup.vb 56 Active

     

    FOLLOWING IS THE FULL CONVERTED CODE:

     

    Imports IdentityModel.Client

    Imports Microsoft.AspNet.Identity

    Imports Microsoft.IdentityModel.Protocols.OpenIdConnect

    Imports Microsoft.IdentityModel.Tokens

    Imports Microsoft.Owin

    Imports Microsoft.Owin.Security

    Imports Microsoft.Owin.Security.Cookies

    Imports Microsoft.Owin.Security.OpenIdConnect

    Imports Owin

    Imports System

    Imports System.Collections.Generic

    Imports System.Configuration

    Imports System.Security.Claims

     

     

    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)

        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

     

     

     

    Expand Post
This question is closed.
Loading
Sample ASP.NET VB sample to use OKTA