Base solution for your next web application

Activities of "Bernard"

Hi,

You need to go to after login like a tenant with OpenIdConnect

Hi I followed this example https://learn.microsoft.com/en-us/training/modules/msgraph-dotnet-core-show-user-emails/1-introduction

Hi,

Thank you for your help, I really appreciate it As the file is large, I will send it to you via Wetransfer.

https://we.tl/t-mXXIpSAVOT

Good luck

Hi,

Same issue with this code :

if (bool.Parse(configuration["Authentication:OpenId:IsEnabled"])) { //if (bool.Parse(configuration["Authentication:AllowSocialLoginSettingsPerTenant"])) //{ // services.AddSingleton<IOptionsMonitor<OpenIdConnectOptions>, TenantBasedOpenIdConnectOptions>(); //}

  services
  // Add support for OpenId authentication
  .AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
  .AddMicrosoftIdentityWebApp(configuration, "Authentication:AzureAd")
  .EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
  .AddMicrosoftGraph(configuration.GetSection("Authentication:DownstreamApi"))
  .AddInMemoryTokenCaches();

  // Require an authenticated user
  //services.AddControllersWithViews(options =>
  //{
  //    var policy = new AuthorizationPolicyBuilder()
  //        .RequireAuthenticatedUser()
  //        .Build();
  //    options.Filters.Add(new AuthorizeFilter(policy));
  //});

  //services
  //    // Add Razor Pages support
  //    .AddRazorPages()

  //    // Add Microsoft Identity UI pages that provide user 
  //    .AddMicrosoftIdentityUI();

  services.AddScoped&lt;GraphProfileClient&gt;();
  services.AddScoped&lt;GraphEmailClient&gt;();
  //services.AddScoped&lt;GraphCalendarClient&gt;();
  //services.AddScoped&lt;GraphFilesClient&gt;();

};

Hi Yes it’s a single project I still running Yarn

Thks

Hi What do you mean by server side ?

Answer

Hi,

Sorry i don't understand how i can achieve this ?

Thks for your help

Hi,

The OpenconnectId and Microsoft graph connection seems to work well now. But I'm facing another issue now. When I want to view emails I am systemically redirected by this method which seems to pose an issue.

ERUDYEntityFrameworkCoreModule

[DependsOn( typeof(AbpZeroCoreEntityFrameworkCoreModule), typeof(ERUDYCoreModule) )] public class ERUDYEntityFrameworkCoreModule : AbpModule { /* Used it tests to skip DbContext registration, in order to use in-memory database of EF Core */ public bool SkipDbContextRegistration { get; set; }

 public bool SkipDbSeed { get; set; }

 public override void PreInitialize()
 {
     if (!SkipDbContextRegistration)
     {
         Configuration.Modules.AbpEfCore().AddDbContext&lt;ERUDYDbContext&gt;(options =>
         {
             if (options.ExistingConnection != null)
             {
                 ERUDYDbContextConfigurer.Configure(options.DbContextOptions,
                     options.ExistingConnection);
             }
             else
             {
                 ERUDYDbContextConfigurer.Configure(options.DbContextOptions,
                     options.ConnectionString);
             }
         });
     }

     // Set this setting to true for enabling entity history.
     Configuration.EntityHistory.IsEnabled = false;

     // Uncomment below line to write change logs for the entities below:
     // Configuration.EntityHistory.Selectors.Add("ERUDYEntities", EntityHistoryHelper.TrackedTypes);
     // Configuration.CustomConfigProviders.Add(new EntityHistoryConfigProvider(Configuration));
 }

 public override void Initialize()
 {
     IocManager.RegisterAssemblyByConvention(typeof(ERUDYEntityFrameworkCoreModule).GetAssembly());
 }

 public override void PostInitialize()
 {
     var configurationAccessor = IocManager.Resolve&lt;IAppConfigurationAccessor&gt;();

     using (var scope = IocManager.CreateScope())
     {
         if (!SkipDbSeed && scope.Resolve&lt;DatabaseCheckHelper&gt;()
                 .Exist(configurationAccessor.Configuration["ConnectionStrings:Default"]))
         {
             SeedHelper.SeedHostDb(IocManager);
         }
     }
 }

}

And the resut email display is :

Have you an idea of what causes this issue ?

Thks very much

Hi Ismail,

I finally found the good way :

// Retrieve required permissions from appsettings string[] initialScopes = configuration.GetValue<string>("DownstreamApi:Scopes")?.Split(' ');

var authenticationBuilder = services.AddAuthentication(options => { options.DefaultScheme = "OpenIdConnect"; options.DefaultChallengeScheme = "AzureAd";

if (bool.Parse(configuration["Authentication:OpenId:IsEnabled"])) { if (bool.Parse(configuration["Authentication:AllowSocialLoginSettingsPerTenant"])) { services.AddSingleton<IOptionsMonitor<OpenIdConnectOptions>, TenantBasedOpenIdConnectOptions>(); }

  authenticationBuilder.AddOpenIdConnect(options =>
  {
      options.ClientId = configuration["Authentication:OpenId:ClientId"];
      options.Authority = configuration["Authentication:OpenId:Authority"];
      options.SignedOutRedirectUri = configuration["App:WebSiteRootAddress"] + "Account/Logout";
      options.ResponseType = configuration["Authentication:OpenId:ResponseType"];

      options.TokenValidationParameters = new TokenValidationParameters()
      {
          ValidateIssuer = bool.Parse(configuration["Authentication:OpenId:ValidateIssuer"])
      };

      options.Events.OnTokenValidated = context =>
      {
          var jsonClaimMappings = new List&lt;JsonClaimMap&gt;();
          configuration.GetSection("Authentication:OpenId:ClaimsMapping").Bind(jsonClaimMappings);

          context.AddMappedClaims(jsonClaimMappings);

          return Task.FromResult(0);
      };

      var clientSecret = configuration["Authentication:OpenId:ClientSecret"];
      if (!clientSecret.IsNullOrEmpty())
      {
          options.ClientSecret = clientSecret;
      }
  })**.AddMicrosoftIdentityWebApp(options =>
  {
      options.ClientId = configuration["Authentication:AzureAd:ClientId"];
      options.Instance= configuration["Authentication:AzureAd:Instance"];
      options.TenantId = configuration["Authentication:AzureAd:TenantId"];
      options.SignedOutRedirectUri = configuration["App:WebSiteRootAddress"] + "Account/Logout";
    
      var clientSecret = configuration["Authentication:AzureAd:ClientSecret"];
      if (!clientSecret.IsNullOrEmpty())
      {
          options.ClientSecret = clientSecret;
      }
  }, null, "AzureAd")
  .EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
  .AddMicrosoftGraph(configuration.GetSection("DownstreamApi"))
  .AddInMemoryTokenCaches();**

};

Showing 41 to 50 of 92 entries