FusionAuth
    • Home
    • Categories
    • Recent
    • Popular
    • Pricing
    • Contact us
    • Docs
    • Login

    Claim not present in .Net

    Scheduled Pinned Locked Moved Unsolved
    Q&A
    3
    6
    945
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ?
      A Former User
      last edited by

      Hi folks,

      After FusionAuth login, I don't have role claims in the .Net Identity. I use the .Net+React POC found here
      https://github.com/FusionAuth/fusionauth-example-asp-net5-react

      This problem is similar to this post
      https://fusionauth.io/community/forum/topic/1485/role-claims-issue-with-openidconnect-netcore5
      However not exactly the same, I use both .Net and React, no razor pages. The solution of the post above doesn't work because AddOpenIdConnect ... OnMessageReceived is never called. Not sure it's normal.

      As I see things in the .Net+React POC, they handle everything in the Session, they don't get anything special in HttpContext.User.Identity , is it normal ?
      Does it mean we can't have Role Claims when using a .Net + React solution ? I would expect the JWT token to convert into a proper .Net Identity.

      If anyone can get Role Claims in the .Net+React POC, please tell how

      joshuaJ 1 Reply Last reply Reply Quote 1
      • joshuaJ
        joshua @A Former User
        last edited by joshua

        @lionel-selosse

        Thanks for the information.

        I might need a bit more context, but it sounds like you are looking to store user identity information outside of a session.

        These two articles may be of initial interest, based on a google search.

        • https://andrewhalil.com/2020/09/14/role-retrieval-from-jwt-token-claims-in-net-core-applications/
        • https://andrewhalil.com/2022/08/09/how-to-retrieve-user-context-from-jwt-bearer-tokens-in-net-core/

        Let us know and we may be able to debug this a little bit further.

        Thanks,
        Josh

        ? 1 Reply Last reply Reply Quote 0
        • joshuaJ joshua referenced this topic on
        • ?
          A Former User @joshua
          last edited by

          @joshua said in Claim not present in .Net:

          I might need a bit more context, but it sounds like you are looking to store user identity information outside of a session.

          Indeed, the default .Net way to handle authentication and roles is of course not keeping user info (data from JWT token) in Session (ISession interface). .Net uses Identity and Claims for those sensitive data. This is where information from the JWT token should normally be stored. But looking at the POC on GitHub, it looks like you guys store this in Session, nothing in Identity and Claims. Am I wrong ?

          1 Reply Last reply Reply Quote 0
          • joshuaJ
            joshua
            last edited by joshua

            @lionel-selosse I am not very familiar with dot net as a language; I would have to review that particular example application.

            We are always open to feedback on our documentation and example applications. There may also be an opportunity to develop an alternative example application making use of other dot net security paradigms/workflows.

            I will check in with the team and let you know if anything else surfaces to relay on.

            Thanks,
            Josh

            ? 1 Reply Last reply Reply Quote 0
            • ?
              A Former User @joshua
              last edited by

              Ok thanks @joshua for your honest reponse 🙂 There is no shame to be new to .Net, it became so different to Java and other technos around. For sure let me know in case something new pops up.

              1 Reply Last reply Reply Quote 1
              • M
                manlio.marchica
                last edited by

                I have the exact same problem. I have a Net6 Web Api project with swagger client configured. I have no claims

                I have AddJwtBearer with this settings

                services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                .AddJwtBearer(options =>
                {
                options.Authority = fusionAuthAuthority;
                options.Audience = fusionAuthAudience;
                options.RequireHttpsMetadata = false; // DEV only!!
                });

                and swagger client configured this way

                services.AddSwaggerGen(c =>
                {
                c.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
                {
                Type = SecuritySchemeType.OAuth2,
                Flows = new OpenApiOAuthFlows
                {
                AuthorizationCode = new OpenApiOAuthFlow
                {
                AuthorizationUrl = new Uri($"{fusionAuthAuthority}oauth2/authorize?audience={fusionAuthAudience}", UriKind.Absolute),
                TokenUrl = new Uri($"{fusionAuthAuthority}oauth2/token", UriKind.Absolute),
                Scopes = new Dictionary<string, string>() { }

                         }
                     }
                 });
                
                 c.AddSecurityRequirement(new OpenApiSecurityRequirement
                 {
                     {
                         new OpenApiSecurityScheme
                         {
                             Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "oauth2" }
                         },
                         Array.Empty<string>()
                     }
                 });
                
                 c.ExampleFilters();
                
                 c.DocumentFilter<OrderTagsDocumentFilter>();
                

                });

                Any updates on this issue or hints ?

                Thanks
                Manlio

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post