Skip to content

Commit

Permalink
remove api authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
kbeaugrand committed Jan 26, 2022
1 parent f363de4 commit fea5a16
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 51 deletions.
16 changes: 5 additions & 11 deletions src/AzureIoTHub.Portal/Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,22 @@ public static async Task Main(string[] args)
builder.RootComponents.Add<App>("#app");

builder.Services.AddHttpClient("api", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();
/*.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>()*/;

builder.Services.AddFileReaderService(o => o.UseWasmSharedBuffer = true);

// Supply HttpClient instances that include access tokens when making requests to the server project
builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("api"));
builder.Services.AddBlazoredModal();

// builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddMudServices();

await ConfigureMsalAuthentication(builder);
await ConfigureOidc(builder);

await builder.Build().RunAsync();
}

private static async Task ConfigureMsalAuthentication(WebAssemblyHostBuilder builder)
private static async Task ConfigureOidc(WebAssemblyHostBuilder builder)
{
var httpClient = new HttpClient() { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) };
var settings = await httpClient.GetFromJsonAsync<OIDCSettings>("OIDCSettings");
Expand All @@ -52,14 +51,9 @@ private static async Task ConfigureMsalAuthentication(WebAssemblyHostBuilder bui
options.ProviderOptions.ClientId = settings.ClientId;

options.ProviderOptions.DefaultScopes.Clear();
options.ProviderOptions.DefaultScopes.Add("openid");
options.ProviderOptions.DefaultScopes.Add("profile");
options.ProviderOptions.DefaultScopes.Add(settings.Scope);
options.ProviderOptions.DefaultScopes.Add($"profile openid {settings.Scope}");

options.ProviderOptions.ResponseType = "code";

options.ProviderOptions.RedirectUri = "authentication/login-callback";
options.ProviderOptions.PostLogoutRedirectUri = "authentication/logout-callback";
options.ProviderOptions.ResponseType = "id_token";
});
}
}
Expand Down
11 changes: 0 additions & 11 deletions src/AzureIoTHub.Portal/Server/Controllers/CommandsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,15 @@
namespace AzureIoTHub.Portal.Server.Controllers
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Azure.Data.Tables;
using AzureIoTHub.Portal.Server.Factories;
using AzureIoTHub.Portal.Server.Helpers;
using AzureIoTHub.Portal.Server.Managers;
using AzureIoTHub.Portal.Server.Mappers;
using AzureIoTHub.Portal.Server.Services;
using AzureIoTHub.Portal.Shared.Models;
using AzureIoTHub.Portal.Shared.Security;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;

[Authorize]
[ApiController]
[Route("api/[controller]")]
[Authorize(Roles = RoleNames.Admin)]
public class CommandsController : ControllerBase
{
private readonly ITableClientFactory tableClientFactory;
Expand Down
14 changes: 0 additions & 14 deletions src/AzureIoTHub.Portal/Server/Controllers/ConfigsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,18 @@

namespace AzureIoTHub.Portal.Server.Controllers
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using AzureIoTHub.Portal.Server.Filters;
using AzureIoTHub.Portal.Server.Helpers;
using AzureIoTHub.Portal.Server.Services;
using AzureIoTHub.Portal.Shared.Models;
using AzureIoTHub.Portal.Shared.Security;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Devices;
using Microsoft.Azure.Devices.Common.Exceptions;
using Microsoft.Azure.Devices.Shared;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;

[Authorize]
[ApiController]
[Route("api/[controller]")]
[Authorize(Roles = RoleNames.Admin)]

public class ConfigsController : ControllerBase
{
private readonly ILogger<ConfigsController> logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@ namespace AzureIoTHub.Portal.Server.Controllers
using AzureIoTHub.Portal.Server.Mappers;
using AzureIoTHub.Portal.Server.Services;
using AzureIoTHub.Portal.Shared.Models;
using AzureIoTHub.Portal.Shared.Security;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;

[Authorize]
[ApiController]
[Route("api/[controller]")]
[Authorize(Roles = RoleNames.Admin)]
public class DeviceModelsController : ControllerBase
{
private const string DefaultPartitionKey = "0";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ namespace AzureIoTHub.Portal.Server.Controllers
using AzureIoTHub.Portal.Server.Mappers;
using AzureIoTHub.Portal.Server.Services;
using AzureIoTHub.Portal.Shared.Models.Device;
using AzureIoTHub.Portal.Shared.Security;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Devices;
using Microsoft.Azure.Devices.Common.Exceptions;
using Microsoft.Azure.Devices.Shared;
using Microsoft.Extensions.Logging;

[Authorize(Roles = RoleNames.Admin)]
[ApiController]
[Route("api/[controller]")]
public class DevicesController : ControllerBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,22 @@ namespace AzureIoTHub.Portal.Server.Controllers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using AzureIoTHub.Portal.Server.Helpers;
using AzureIoTHub.Portal.Server.Interfaces;
using AzureIoTHub.Portal.Server.Managers;
using AzureIoTHub.Portal.Server.Services;
using AzureIoTHub.Portal.Shared.Models;
using AzureIoTHub.Portal.Shared.Security;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Devices;
using Microsoft.Azure.Devices.Common.Exceptions;
using Microsoft.Azure.Devices.Provisioning.Service;
using Microsoft.Azure.Devices.Shared;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

[Authorize]
[ApiController]
[Route("api/[controller]")]
[Authorize(Roles = RoleNames.Admin)]
public class GatewaysController : ControllerBase
{
private readonly ILogger<GatewaysController> logger;
Expand Down
2 changes: 2 additions & 0 deletions src/AzureIoTHub.Portal/Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void ConfigureServices(IServiceCollection services)
opts.Authority = configuration.OIDCAuthority;
});

/*
services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddOpenIdConnect(opts =>
Expand All @@ -66,6 +67,7 @@ public void ConfigureServices(IServiceCollection services)
{
opts.Filters.Add(new ApiRequiredScopeFilter(configuration));
});
*/

services.AddRazorPages();

Expand Down

0 comments on commit fea5a16

Please sign in to comment.