Giter Site home page Giter Site logo

jonathansear / get-claims-from-azure-b2c-jwt-token Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 844 KB

For applications leveraging Azure B2C which want a clean way to read the claims, you have passed in your workflow back to the application.

License: MIT License

C# 50.03% HTML 35.27% CSS 12.59% JavaScript 2.11%
azure-b2c claim mapper azure azure-active-directory-b2c active-directory claimsprincipal b2c identity

get-claims-from-azure-b2c-jwt-token's Introduction

Convert the ClaimsPrincipal object returned by Azure B2C into this adapter to read the user claims

Introduction

For applications leveraging Azure B2C which want a clean way to read the claims you have passed in your workflow back to the application.

This small lightweight library unpicks all the claims in the ClaimsPrincipal.

Usage

ClaimProperties userClaims = _tokenManager.ConvertClaims(User.Identities.FirstOrDefault().Claims);

string name = userClaims.name;

string jobTitle = userClaims.jobTitle;

Setup

  1. Your application must already be using Azure B2C. You should see something similar startup.cs.

     services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme)
                 .AddAzureADB2C(options => Configuration.Bind(CurrentEnvironment.IsDevelopment() ? "AzureAdB2CDev" : "AzureAdB2C", options));
  2. Add a project reference to the Managers class libary from within this repo.

  3. Register the dependency in your startup.cs.

public void ConfigureServices(IServiceCollection services)
      {
          //Add Token Manager to dependency injection 
          services.Add(new ServiceDescriptor(typeof(ITokenManager), new TokenManager()));
      }
  1. Finally Inject it into your controller
        ITokenManager _tokenManager;

        public HomeController(ITokenManager tokenManager)
        {
            _tokenManager = tokenManager;
        }

        public IActionResult Index()
        {
            ClaimProperties userClaims = _tokenManager.ConvertClaims(User.Identities.FirstOrDefault().Claims);

            string name = userClaims.name;

            string jobTitle = userClaims.jobTitle;

            return View();
        }
   

get-claims-from-azure-b2c-jwt-token's People

Contributors

jonathansear avatar

Watchers

 avatar

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.