Handling Security Token Issues in Azure AD
Handling Security Token Issues in Azure AD
1
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
2
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
Multi-tenant application - A multi-tenant application is intended for use in many organizations, not just one
organization. These are typically software-as-a-service (SaaS) applications written by an independent software
vendor (ISV). Multi-tenant applications need to be provisioned in each directory where they will be used,
which requires user or administrator consent to register them. This consent process starts when an
application has been registered in the directory and is given access to the Graph API or perhaps another web
API. When a user or administrator from a different organization signs up to use the application, they are
presented with a dialog that displays the permissions the application requires. The user or administrator can
then consent to the application, which gives the application access to the stated data, and finally registers the
application in their directory.
EndPoint: [Link]
3
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
When you register an Azure AD application in the Azure portal, two objects are created in your Azure AD tenant:
1. An application object
2. A service principal object
Azure AD application is defined by its one and only application object, which resides in the Azure AD tenant where
the application was registered, known as the application's “home” tenant.
To access resources that are secured by an Azure AD tenant, the entity that requires access must be represented
by a security principal. This is true for both users (user principal) and applications (service principal). The security
principal defines the access policy and permissions for the user or application in the Azure AD tenant. This enables
core features such as authentication of the user or application during sign-in and authorization during resource
access.
Consider the application object as the global representation of your application for use across all tenants, and the
service principal as the local representation for use in a specific tenant. An application object therefore has a 1:1
relationship with the software application, and a 1:many relationships with its corresponding service principal
object(s).
4
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
5
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
For clients that need to access protected resources, Azure AD provides the Active Directory Authentication Library
(ADAL). ADAL v1.0 enables application developers to authenticate users to cloud or on-premises Active Directory
(AD) and obtain tokens for securing API calls.
ADAL makes authentication easier for developers through features such as:
• Configurable token cache that stores access tokens and refresh tokens.
• Automatic token refresh when an access token expires, and a refresh token is available.
• Support for asynchronous method calls.
Available in multiple languages such as:
• C#
• JavaScript
• Objective C
• Java
• Python
class Program
{
static string appId = "457ffee2-d5f2-46a9-a26a-fd146b9952e6";
static string secret = "ZRFmm_57E.g_64CTxd.XO921l.59x52rSn";
static string tenantId = "82d8af3b-d3f9-465c-b724-0fb186cc28c7";
static void Main(string[] args)
{
var context = new AuthenticationContext("[Link] + tenantId);
var credential = new ClientCredential(clientId: appId, clientSecret: secret);
AuthenticationResult result = [Link](appId, credential).Result;
if (result == null)
throw new InvalidOperationException("Failed to obtain the JWT token");
var token = [Link];
}
6
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
Limitation of ADAL:
Can authenticate against only work and school accounts provisioned in Azure AD. Will not work with individual
Microsoft Account.
7
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
8
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
1. Confidential client applications are apps that run on servers (Web Apps, Web API apps, or even
service/daemon apps). A web app is the most common confidential client. The client ID is exposed through the
web browser, but the secret is passed only in the back channel and never directly exposed.
2. Public client applications are apps that run on devices or desktop computers or in a web browser SPA. They're
not trusted to safely keep application secrets, so they only access Web APIs on behalf of the user. (They
support only public client flows.) Public clients can't hold configuration-time secrets, so they don't have client
secrets. Uses the MSAL PublicClientApplication class.
9
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
Authentication flows:
Authorization code: Native and web apps securely obtain tokens in the name of the user.
Interactive: User authenticates by using a web browser. Mobile and desktops applications call Microsoft
Graph in the name of a user.
Client credentials: Service applications run without user interaction.
On-behalf-of: Application authenticates on behalf of a user.
Implicit: Used in browser-based applications.
Device code: Enables sign-in to a device by using another device that has a browser.
Integrated Windows: Windows computers silently acquire an access token when they are domain joined.
Username/password: The application signs in a user by using their username and password.
string[] scopes = { "[Link]" };
AuthenticationResult result = await [Link](scopes).ExecuteAsync();
Organizations that develop their own line-of-business (LOB) applications can protect access to those applications
by using Azure AD. Developers can enable their own custom applications to use Azure AD, and obtain the same
features that are available in the Azure AD gallery applications.
11
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
2. Provide Name="MySecuredWebApp", Redirect URI (optional) Select a platform = Web, Sign-on URL:
[Link] (Run the web application and replace the 44336 port with what ever is
assigned for your application)
3. Azure Portal Azure Active Directory App registrations Select DssDemoApp Settings Properties
4. Copy Application ID
12
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
"TenantId": "82d8af3b-d3f9-465c-b724-0fb186cc28c7",
"ClientId": "da1ebcac-01ec-4053-8078-93b057545eb6",
"CallbackPath": "/signin-oidc"
}
}
5. Edit Views/Home/[Link]
<link href="@[Link]("~/Content/[Link]")" rel="stylesheet" type="text/css" />
<h3>Main Claims:</h3>
<table class="table table-striped table-bordered table-hover">
<tr><td>Username</td><td>@[Link]</td></tr>
<tr><td>TenantId</td><td>@[Link]</td></tr>
</table>
<br />
<h3>All Claims:</h3>
<table class="table table-striped table-bordered table-hover table-condensed">
@foreach (var claim in (([Link]) [Link]).Claims)
{
<tr><td>@[Link]</td><td>@[Link]</td></tr>
}
13
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
</table>
<br />
<br />
@[Link]("Sign out", "SignOut", "Home", null, new { @class = "btn btn-primary" })
Multi Tenant Option: Configure your application to allow sign-ins of work and school accounts from any
company or organization (multi-tenant)
1. Go back to Microsoft Azure portal - App registrations and locate the application you registered.
2. Select Authentication select Supported account types = Accounts in any organizational directory.
3. Select Save.
4. Edit [Link]
14
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
"AzureAd": {
"Instance": "[Link] ",
"ClientId": "29d2c719-e33d-4ca4-a2eb-cd21459e701b",
"TenantId": "common",
"CallbackPath": "/signin-oidc"
}
Java Example:
[Link]
[Link]
app-with-azure-active-directory
[Link]
directory-developer-guide
Calling a Web API from a Daemon Application (server to server call) – Authentication Flow: Client Credentials
To Demonstrate how the Application can use its own Identity (not its loggedin users) to access the WebAPI
Application roles are exposed by web APIs called by daemon applications (that calls your web API on their own
behalf).
16
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
17
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
using System;
using [Link];
using [Link];
using [Link];
using [Link];
class Program
{
private const string _clientId = "<client id of AD App for ConApp";
private const string _tenantId = "82d8af3b-d3f9-465c-b724-0fb186cc28c7";
public static async Task Main(string[] args)
{
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder
.Create(_clientId)
.WithAuthority([Link], _tenantId)
.WithClientSecret("A2Y_CQWo_NxtNY9..WNOolLe7k8y318uZ2")
.Build();
19
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
Java Example:
[Link]
Invoking a Secure API from Client using Users Identity - Authentication Flow: Interactive
To Demonstrate how the Application can use its logged-in users identity to access the WebAPI
20
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
[Link]();
[Link]();
}
4. Use [Authorize] attribute whereever required.
5. Add the following to WebAPI Method to check if the request has the scope user_impersonation or not
[HttpGet]
public IEnumerable<WeatherForecast> Get()
21
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
{
//[Link](claim => [Link] == "name").Value
var apiClaim = [Link](c => [Link] == "[Link] &&
[Link]("user_impersonation")).FirstOrDefault();
if (apiClaim == null)
{
throw new ApplicationException("Unauthorized-The Scope claim does not contain 'user_impersonation' or
scope claim not found");
}
Step3: Create an Azure AD Application for Client Application (Mobile App or Console App)
1. Azure Portal Active Directory App Registrations New registration Name=MyConApp
2. Name = MyDemoApp, Supported Account Types = Accounts in this organizational directory only
3. Redirect URL: Public client/native (mobile & desktop), [Link]
4. API Permissions Add a permission My APIs Select MyWebAPI Check user_impersonation Add
permission.
22
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
using [Link];
using [Link];
class Program
{
private const string _clientId = "2226001b-e403-4f74-b9b6-76133a83d990";
private const string _tenantId = "82d8af3b-d3f9-465c-b724-0fb186cc28c7";
public static async Task Main(string[] args)
{
IPublicClientApplication app = PublicClientApplicationBuilder
.Create(_clientId)
.WithAuthority([Link], _tenantId)
.WithRedirectUri("[Link]
.Build();
//Custom API
string[] scopes1 = { "[Link] };
AuthenticationResult result1 = await [Link](scopes1).ExecuteAsync();
var client1 = new HttpClient();
var authHeader1 = new AuthenticationHeaderValue("Bearer", [Link]);
23
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
[Link] = authHeader1;
string endpoint1 = "[Link] //URL of WebAPI
var response1 = await [Link](endpoint1);
string json1 = await [Link]();
[Link](json1);
}
}
Note: The AcquireTokenSilent will return the token it already has in cache if it is still valid or get a new one using
refresh token or cookies in case implicit id_token. You can only make this call however if you are sure that you
already have an access token or use has already been authenticated by a previous non-silent acquire token call.
Accessing Secure Web API from Web App using Logged-In Users Identity
24
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
25
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
e) Supported account types = Accounts in this organizational directory only (Personal Directory only -
Single tenant)
f) Redirect URI = <Leave it as blank>
12. Authentication Under Implicit Grant check = ID tokens
13. Overview Application ID URI = [Link]
14. Expose an API + Add a Scope
i) for Scope name use user_impersonation
j) Ensure the Admins and users option is selected for Who can consent
k) in Admin consent display name type Access My Web API as a Admin
l) in Admin consent description type Accesses the My Web API as a Admin
m) in User consent display name type Access My Web API as a user
n) in User consent description type Accesses the My Web API as a user
o) Keep State as Enabled
p) Select Add scope
26
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
"AzureAd": {
"Instance": "[Link]
"Domain": "[Link]",
"TenantId": "82d8af3b-d3f9-465c-b724-0fb186cc28c7",
"ClientId": "2f2e4e4e-aa57-4e07-83bd-a9853b55eb67"
"Audience": "[Link]
}
21. To [Link] ConfigureServices method add the following line
[Link](Configuration, "AzureAd");
22. Add the following to Configure method
[Link]();
[Link]();
23. A common requirement for web APIs is to validate the "scopes" present in the token to ensure that the user
has consented to the permissions required to access the WebAPI.
[HttpGet]
[Authorize]
public IEnumerable<WeatherForecast> Get()
{
var apiClaim = [Link](c => [Link] == "[Link] &&
[Link]("user_impersonation")).FirstOrDefault();
if (apiClaim == null)
{
throw new ApplicationException("Unauthorized-
The Scope claim does not contain 'user_impersonation' or scope claim not found");
}
var rng = new Random();
return [Link](1, 5).Select(index => new WeatherForecast
{
Date = [Link](index),
TemperatureC = [Link](-20, 55),
Summary = Summaries[[Link]([Link])]
27
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
})
.ToArray();
}
28
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
29
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
return View(cols);
}
}
Role-based authorization
Role-based authorization is an authorization approach in which user permissions are managed and enforced by an
application based on user roles. If a user has a role that is required to perform an action, access is granted;
otherwise, access is denied. When an identity is created, it may belong to one or more roles. For example, Holly
may belong to the Administrator and User roles, whereas Adam may belong only to the User role. How these roles
are created and managed depends on the backing store of the authorization process.
Roles are specific to the application. The role claims for one application are not sent to another application.
If the customer removes the application from their AD tenant, the roles go away.
The application doesn't need any extra Active Directory permissions, other than reading the user's profile.
Drawbacks:
Customers without Azure AD Premium cannot assign security groups to roles. For these customers, all user
assignments must be done by an AD administrator.
If you have a backend web API, which is separate from the web app, then role assignments for the web app
don't apply to the web API.
Steps To Implement
Azure AD App registrations Select the app Manifest Edit the Manifest (Search “appRoles” and edit)
"appRoles": [
{
"allowedMemberTypes": [
"User"
],
"description": "This is Demo Role1",
"displayName": "DemoRole1",
"id": "1b4f816e-5eaf-48b9-8613-7923830595ty",
"isEnabled": true,
"value": "DemoRole1"
},
{
"allowedMemberTypes": [
"User"
],
"description": "This is Demo Role2",
"displayName": "DemoRole2",
"id": "c20e145e-5459-4a6c-a074-b942bbd4cab1",
"isEnabled": true,
"value": "DemoRole2"
}
],
31
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
Note: The value property appears in the role claim. The id property is the unique identifier for the defined role.
Always generate a new GUID value for id.
Assign users.
When a new customer signs up, the application is registered in the customer's AD tenant. At this point, an AD
admin for that tenant can assign users to roles.
Azure AD Enterprise Application Select the Application Users and groups Add user Select User and
Select Role
Roles are exposed to the developer through the IsInRole method on the ClaimsPrincipal class. Role-based Instead,
write code that checks whether a particular claim value is present:
Authorization checks are declarative—the developer embeds them within their code, against a controller or an
action within a controller, specifying roles that the current user must be a member of to access the requested
resource.
For example, the following code limits access to any actions on the DemoController to users who are members of
the DemoRole1 role:
[Authorize(Roles = "DemoRole1")]
public class DemoController : Controller { }
32
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
If you apply multiple attributes, an accessing user must be a member of all the roles specified. The following
sample requires that a user be a member of both the DemoRole1 and DemoRole2 roles:
[Authorize(Roles = "DemoRole1")]
[Authorize(Roles = "DemoRole2")]
public class ControlPanelController : Controller { }
You can further limit access by applying additional role authorization attributes at the action level:
[Authorize(Roles = "DemoRole1, DemoRole2")]
public class ControlPanelController : Controller
{
public ActionResult SetTime()
{}
[Authorize(Roles = "DemoRole2")]
public ActionResult ShutDown()
{}
}
In the previous code snippet, members of either the DemoRole1 role or the DemoRole2 role can access the
controller and the SetTime action, but only members of the DemoRole2 role can access the ShutDown action.
You can also lock down a controller but allow anonymous, unauthenticated access to individual actions:
[Authorize]
public class ControlPanelController : Controller
{
public ActionResult SetTime()
{}
[AllowAnonymous]
public ActionResult Login()
{}
}
Policy Syntax
33
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
In [Link] Core Role requirements can also be expressed using the Policy syntax, where a developer registers a
policy at startup as part of the authorization service configuration. This normally occurs in ConfigureServices() in
your [Link] file:
public void ConfigureServices(IServiceCollection services)
{
[Link]();
[Link](options => {
[Link]("RequireAdministratorRole", policy => [Link]("Administrator"));
});
}
Policies are applied using the Policy property on the AuthorizeAttribute attribute:
[Authorize(Policy = "RequireAdministratorRole")]
public IActionResult Shutdown()
{
return View();
}
If you want to specify multiple allowed roles in a requirement, you can specify them as parameters to the
RequireRole method:
[Link]("ElevatedRights", policy => [Link]("Administrator", "PowerUser",
"BackupAdministrator"));
This example authorizes users who belong to the Administrator, PowerUser, or BackupAdministrator roles.
34
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
Stores user information in the application database, where it can get out of sync with the tenant's AD
directory, as users are added or removed.
35
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
If you have a controller that's protected by the AuthorizeAttribute attribute but want to allow anonymous access
to particular actions, you apply the AllowAnonymousAttribute attribute:
[Authorize(Policy = "EmployeeOnly")]
public class VacationController : Controller
{
public ActionResult VacationBalance()
{}
[AllowAnonymous]
public ActionResult VacationPolicy()
{}
36
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
Most claims come with a value. You can specify a list of allowed values when creating the policy. The following
example succeeds only for employees whose employee number is 1, 2, 3, 4 or 5:
public void ConfigureServices(IServiceCollection services)
{
[Link]();
[Link](options => {
[Link]("ValidIssuers", policy => [Link]("iss",
"[Link]
"[Link]
});
}
[Authorize(Policy = "ValidIssuers")]
public void Foo()
{}
37
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
/me
o /me/messages
o /me/drive
/user
/group
1. For the CRUD methods GET and DELETE, no request body is required.
2. The POST, PATCH, and PUT methods require a request body, usually specified in JSON format, that contains
additional information, such as the values for properties of the resource.
Sample URL's:
[Link]
[Link]
[Link]
[Link]
skills
Walkthrough
1. Configure Permission in Azure AD Application:
a) Go to App Registration Select the App API Permission
b) + Add a permission Microsoft Graph Delegated permissions
c) Check [Link] (Read all users full profiles) Add permissions
2. Create a Console Application
39
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
class Program
{
private const string _clientId = "fd5b684c-2d9d-4160-873a-b7e92b784ea1";
private const string _tenantId = "ef404960-95a9-49fb-be86-72acd7a3bc27";
public static async Task Main (string[] args)
{
var app = PublicClientApplicationBuilder
.Create(_clientId)
.WithAuthority([Link], _tenantId)
.WithRedirectUri("[Link]
.Build();
40
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Deccansoft Software Services – Microsoft Azure Azure Active Directory
}
}
}
Authenticating to and querying Microsoft Graph by using MSAL and .NET SDKs
[Link]
DevelopingSolutionsforMicrosoftAzure/blob/master/Instructions/Labs/AZ-204_06_lab.md
41
Deccansoft Software Services [Link]: 153, A/4, Balamrai, Secunderabad-500003 TELANGANA, NDIA.
[Link] | [Link]
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)