Ask Your Question
3

How can I grant permission for accessing resources in another tenant using AuthorizeForScopes?

asked 2023-02-24 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-03-26 19:00:00 +0000

lalupa gravatar image

In order to grant permission for accessing resources in another tenant using AuthorizeForScopes, you need to follow these steps:

  1. Add the AzureAd package to your project.

  2. Configure the Authentication settings in your Startup.cs file to include the TenantId of the other tenant. For example:

services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
        .AddAzureAD(options => Configuration.Bind("AzureAd", options));

options.CallbackPath = "/signin-oidc";
options.TenantId = "ANOTHER_TENANT_ID"; // add the TenantId of the other tenant
options.Instance = "https://login.microsoftonline.com/";
options.ClientId = Configuration["AzureAd:ClientId"];
options.ClientSecret = Configuration["AzureAd:ClientSecret"];
  1. Use the AuthorizeForScopes attribute in your Controllers or Actions to grant access to specific scopes. For example:
[AuthorizeForScopes(Scopes = new[] { "https://ANOTHER_TENANT_NAME.onmicrosoft.com/scope1", "https://ANOTHER_TENANT_NAME.onmicrosoft.com/scope2" })]
public async Task<IActionResult> MyAction()
{
    // code goes here
}
  1. Finally, make sure that the App Registration in the other tenant has been configured to expose the required scopes. You can do this by navigating to the Expose an API section in the App Registration portal and adding the required scopes.
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-02-24 11:00:00 +0000

Seen: 9 times

Last updated: Mar 26 '23