Custom Role with .NET Core 3 Azure AD Authentication

Aaron Rumford

I have a minimally functioning .NET Core 3 Web app using Azure AD for Authentication but I am trying to figure out how to use my own custom roles in my own SQL database for authorization.

Ultimately, I want to verify the user, then get their associated Role from my DB and create policies from there. I'm not afraid to research, but my searches are not pulling up anything that looks right. Can anyone point me in the right direction?

Rohit Saigal

AFAIK the closest Azure AD feature helpful for your requirement would be Application Roles.

You can read more details about it on Microsoft Docs here - Application Roles

Here is a related code sample - Add authorization using app roles & roles claims to an ASP.NET Core web app

To put it briefly, you will be able to define roles specific to your application's Azure AD manifest. Later you can assign these roles to users from Azure Portal or use Microsoft Graph API.

"appRoles": [
  {
    "allowedMemberTypes": [
      "User"
    ],
    "description": "Creators can create Surveys",
    "displayName": "SurveyCreator",
    "id": "1b4f816e-5eaf-48b9-8613-7923830595ad",
    "isEnabled": true,
    "value": "SurveyCreator"
  },
  {
    "allowedMemberTypes": [
      "User"
    ],
    "description": "Administrators can manage the Surveys in their tenant",
    "displayName": "SurveyAdmin",
    "id": "c20e145e-5459-4a6c-a074-b942bbd4cfe1",
    "isEnabled": true,
    "value": "SurveyAdmin"
  }
],

Note that role definitions themselves and information about which users have been assigned what role will all be in Azure AD (not your SQL database as you've mentioned in your question).

Now at the time of signing into your web app, you will get roles as a collection of claims with the incoming access token.

Here is another good documentation that explains both Role based and Resource based authorization with a sample and uses authorization policies.


In case none of this makes sense for your application, you could always implement something custom and store role information as well as assignments in your application database.

Azure AD will not help much with defining or assigning roles in that scenario. You will need to maintain a map between users and their roles in a custom way. If it makes sense you could use RoleManager class.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to specify custom logout URL when using Azure AD authentication in .NET core

分類Dev

How to redirect after Azure AD authentication to different controller action in ASP Net Core MVC

分類Dev

ASP.NET Core 2.2의 Azure AD 인증

分類Dev

Custom Authentication using legacy user table in Asp.Net Core

分類Dev

Is it possible to have both Azure AD and Individual Account authentication in one ASP.NET MVC application?

分類Dev

CORS error when adding Azure AD authentication

分類Dev

Execute code after Azure AD Authentication

分類Dev

Using Azure Active Directory authentication in ASP.NET Core 2.0 from Web App to Web API

分類Dev

Azure AppServiceとしてBlazorhostedASP.NET Core 3

分類Dev

asp.net identity with custom role

分類Dev

Firebase Authentication with Azure AD B2C

分類Dev

Asp.Net Core Azure AD V1.0JWT認証の無効な署名

分類Dev

ASP.Net Core SAML authentication

分類Dev

ASP.Net Core SAML authentication

分類Dev

ASP.Net Core SAML authentication

分類Dev

ASP.NET Core 2.0 authentication middleware

分類Dev

Windows Authentication with asp.net core

分類Dev

Windows Authentication in .net Core 2.1 application

分類Dev

custom domain mapping for azure mvc role works for main page

分類Dev

.NET CoreのAzure WebJob

分類Dev

Role Authentication with Express

分類Dev

ASP.NET MVC 4 - Custom Membership & Role Entities Not Updating

分類Dev

Role based authorization in ASP.NET Core 3.1 with Identity and ExternalLogin

分類Dev

Angular / .net core 3.1 Get Role Claim from JWT

分類Dev

Azure AD B2C OpenID Connect and SAML 2.0 read role claims

分類Dev

Azure ADを使用したAPIバックエンド(.NET Core)での認証の基本

分類Dev

Azure AD / signin-oidc 404-.NET Core2.0を使用したNGINXリバースプロキシ

分類Dev

.NET Core MVCの複数の認証タイプ(Azure ADを含む)の単一のログインページ

分類Dev

Azure ADマルチテナント、JWTトークンを使用した.Net Core Web API

Related 関連記事

  1. 1

    How to specify custom logout URL when using Azure AD authentication in .NET core

  2. 2

    How to redirect after Azure AD authentication to different controller action in ASP Net Core MVC

  3. 3

    ASP.NET Core 2.2의 Azure AD 인증

  4. 4

    Custom Authentication using legacy user table in Asp.Net Core

  5. 5

    Is it possible to have both Azure AD and Individual Account authentication in one ASP.NET MVC application?

  6. 6

    CORS error when adding Azure AD authentication

  7. 7

    Execute code after Azure AD Authentication

  8. 8

    Using Azure Active Directory authentication in ASP.NET Core 2.0 from Web App to Web API

  9. 9

    Azure AppServiceとしてBlazorhostedASP.NET Core 3

  10. 10

    asp.net identity with custom role

  11. 11

    Firebase Authentication with Azure AD B2C

  12. 12

    Asp.Net Core Azure AD V1.0JWT認証の無効な署名

  13. 13

    ASP.Net Core SAML authentication

  14. 14

    ASP.Net Core SAML authentication

  15. 15

    ASP.Net Core SAML authentication

  16. 16

    ASP.NET Core 2.0 authentication middleware

  17. 17

    Windows Authentication with asp.net core

  18. 18

    Windows Authentication in .net Core 2.1 application

  19. 19

    custom domain mapping for azure mvc role works for main page

  20. 20

    .NET CoreのAzure WebJob

  21. 21

    Role Authentication with Express

  22. 22

    ASP.NET MVC 4 - Custom Membership & Role Entities Not Updating

  23. 23

    Role based authorization in ASP.NET Core 3.1 with Identity and ExternalLogin

  24. 24

    Angular / .net core 3.1 Get Role Claim from JWT

  25. 25

    Azure AD B2C OpenID Connect and SAML 2.0 read role claims

  26. 26

    Azure ADを使用したAPIバックエンド(.NET Core)での認証の基本

  27. 27

    Azure AD / signin-oidc 404-.NET Core2.0を使用したNGINXリバースプロキシ

  28. 28

    .NET Core MVCの複数の認証タイプ(Azure ADを含む)の単一のログインページ

  29. 29

    Azure ADマルチテナント、JWTトークンを使用した.Net Core Web API

ホットタグ

アーカイブ