Giter Site home page Giter Site logo

Comments (7)

laura-rodriguez avatar laura-rodriguez commented on June 11, 2024 2

OIDC and JWT events are now exposed. This feature is available in Okta.AspNet 2.0.0 and Okta.AspNetCore 4.0.0. Fixed in #187.

from okta-aspnet.

thepherm avatar thepherm commented on June 11, 2024 1

Thank you!

from okta-aspnet.

nbarbettini avatar nbarbettini commented on June 11, 2024

Hey @jraadt! Let me know if I am understanding your scenario correctly:

  1. Your client/frontend app signs a user in and gets a token from Okta
  2. This token is used to make authorized API calls from the frontend to your API
  3. This token is also used to establish a connection from the client to a SignalR hub on your API
  4. The SignalR JS client doesn't send the Authorization: Bearer header (it sends tokens in the query string instead) so in this case you need to customize how the middleware pulls the token out of the request.

from okta-aspnet.

jraadt avatar jraadt commented on June 11, 2024

@nbarbettini That's exactly right.

from okta-aspnet.

chillitom avatar chillitom commented on June 11, 2024

👍 this would be extremely useful

will the associated PR be merged?

from okta-aspnet.

chillitom avatar chillitom commented on June 11, 2024

Here's a workaround for anyone waiting on the PR.

using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.DependencyInjection;
using Okta.AspNet.Abstractions;
using System;

namespace SignalR.Okta.Fix {

    // these customizations are required to get Okta and SignalR working nicely together
    // https://github.com/okta/okta-aspnet/issues/71
    // https://docs.microsoft.com/it-it/aspnet/core/signalr/authn-and-authz?view=aspnetcore-5.0

    public class ExtendedOktaWebApiOptions : OktaWebApiOptions {
        public JwtBearerEvents Events { get; set; }
    }

    public static class OktaAuthenticationOptionsExtensions {

        /// <summary>
        /// Configures Okta for Web API apps.
        /// </summary>
        /// <param name="builder">The application builder.</param>
        /// <param name="options">The Okta Web API options.</param>
        /// <returns>The authentication builder.</returns>
        public static AuthenticationBuilder AddOktaWebApi(this AuthenticationBuilder builder, ExtendedOktaWebApiOptions options) {
            if (builder == null) {
                throw new ArgumentNullException(nameof(builder));
            }

            new OktaWebApiOptionsValidator().Validate(options);

            return AddJwtValidation(builder, options);
        }

        private static AuthenticationBuilder AddJwtValidation(AuthenticationBuilder builder, ExtendedOktaWebApiOptions options) {
            var issuer = UrlHelper.CreateIssuerUrl(options.OktaDomain, options.AuthorizationServerId);

            var tokenValidationParameters = new DefaultTokenValidationParameters(options, issuer) {
                ValidAudience = options.Audience,
            };

            builder.AddJwtBearer(opt => {
                opt.Audience = options.Audience;
                opt.Authority = issuer;
                opt.TokenValidationParameters = tokenValidationParameters;
                opt.BackchannelHttpHandler = new OktaHttpMessageHandler("okta-aspnetcore", typeof(OktaAuthenticationOptionsExtensions).Assembly.GetName().Version, options);

                opt.SecurityTokenValidators.Clear();
                opt.SecurityTokenValidators.Add(new StrictSecurityTokenValidator());

                opt.Events = options.Events;
            });

            return builder;
        }
    }
}

from okta-aspnet.

laura-rodriguez avatar laura-rodriguez commented on June 11, 2024

Hi @chillitom,

Thanks for your question and for providing a workaround for folks that are waiting for this 💯 .

We have a plan to expose all the events, but I can't share an ETA at the moment, since the .NET team is currently working on different projects.

Thank you so much for your patience!

from okta-aspnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.