asp.net-core

Can't authorize token from Client Credentials Authentication Microsoft AD

我与影子孤独终老i 提交于 2021-02-11 14:56:48
问题 So I have built an Application using ASP Net Core. here is my code services.AddAuthentication(AzureADDefaults.JwtBearerAuthenticationScheme) .AddAzureADBearer(options => Configuration.Bind("AzureAd", options)); services.Configure<JwtBearerOptions>(AzureADDefaults.JwtBearerAuthenticationScheme, options => { // This is a Microsoft identity platform web API. options.Authority += "/v2.0"; // The web API accepts as audiences both the Client ID (options.Audience) and api://{ClientID}. options

ImageSharp.Web - resize image by querystring in Asp.Net Core 3.1

╄→尐↘猪︶ㄣ 提交于 2021-02-11 14:48:14
问题 I am trying to use ImageSharp.Web to resize images through querystring parameters eg: http://localhost:5001/content/photo/img.jpg?width=800&height=600 I created a new MVC Asp.Net Core 3.1 project, installed the packages and followed the Documentation I tried the minimum configuration described and several variations, but it seems that the middleware is not intercepting the image request. I always get the original image and no error is triggered. Am I missing something? What would be the

How to configure Swashbuckle to ignore property on model for a specific api version only

守給你的承諾、 提交于 2021-02-11 14:39:48
问题 I needed to add a property to a model and I have implemented what is suggested in the selected answer here and it's working in that it removes the property I have tagged with SwaggerIgnorePropertyAttribute attribute of the model. My question is , if I have several API versions of my application,how to remove it from the swagger doc/schema for certain versions? I only care not to see the added property in swagger. I only really have 1 version of the model across the application even though I

Need to check of jwt token is valid/expired in asp.net core

本小妞迷上赌 提交于 2021-02-11 14:32:29
问题 In order to generate JWT token I am using the following code: var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_consumerConfiguration.SecretKey); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "ConsumerId") }), Expires = DateTime.Now.AddMinutes(1), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token =

A kind of integration testing in ASP.NET Core, with EF and AutoMapper

对着背影说爱祢 提交于 2021-02-11 14:32:29
问题 I'm trying to test the path from my ASP.NET Core Controller to the DB, through repository which includes the usage of AutoMapper. Here's my repository: using System; using System.Linq; using AutoMapper; using DS.DTO.MasterData; using DS.Utilities.DSExceptions; using Microsoft.Extensions.Logging; using Omu.ValueInjecter; namespace DS.MasterData.Repositories { public class PersonFactRepository : IPersonFactRepository { private readonly Database.MasterDataContext dbContext; private readonly

Reading HttpContext.Request as object?

旧巷老猫 提交于 2021-02-11 14:30:28
问题 My base Request class looks like this: public class GetAllProjectsQuery : QueryBase<ProjectsListModel> { } public abstract class QueryBase<T> : UserContext, IRequest<T> // IRequest is MediatR interface { } public abstract class UserContext { public string ApplicationUserId { get; set; } // and other properties } I want to write a middleware to my .NET Core 3.1 WebApi that will grab JWT from request header amd read ApplicationUserId from it. I started to code something: public class

Reading HttpContext.Request as object?

橙三吉。 提交于 2021-02-11 14:28:44
问题 My base Request class looks like this: public class GetAllProjectsQuery : QueryBase<ProjectsListModel> { } public abstract class QueryBase<T> : UserContext, IRequest<T> // IRequest is MediatR interface { } public abstract class UserContext { public string ApplicationUserId { get; set; } // and other properties } I want to write a middleware to my .NET Core 3.1 WebApi that will grab JWT from request header amd read ApplicationUserId from it. I started to code something: public class

Migrating One-to-Many to Many-to-Many with the new EF Core 5.0

谁说我不能喝 提交于 2021-02-11 14:22:38
问题 I have an ASP.NET Core 5 project (migrated from ASP.NET Core 3.1). The project uses EF Core. EF Core 5 has built-in support for Many-to-Many. The main reason I first migrated from 3.1 to 5.0. Now my project has a One-to-Many relationship, which I want to convert to a Many-to-Many. Is such a relationship migration possible? Current code: public class File { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] [Key] public int Id { get; set; } [DatabaseGenerated(DatabaseGeneratedOption

How to acquire a token with Azure AD and MSAL in ASP.NET

两盒软妹~` 提交于 2021-02-11 14:18:29
问题 I'm trying to authenticate a token using Azure AD. In a console application , I have no problem with this thanks to IConfidentialClientApplication: static void Main(string[] args) { Console.WriteLine("Making the call..."); RunAsync().GetAwaiter().GetResult(); } private static async Task RunAsync() { AuthConfig config = AuthConfig.ReadJsonFromFile("appsettings.json"); IConfidentialClientApplication app; app = ConfidentialClientApplicationBuilder.Create(config.ClientId) .WithClientSecret(config

ps not fount when attaching .Net Core WebApi to Docker container

萝らか妹 提交于 2021-02-11 13:50:48
问题 I am trying to debug my .Net Core webApi project using Docker. However, I am struggling to make it work. I was following this link, to attached my .Net Core app on Docker using VS Code. This is my Dockerfile FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env #install debugger for NET Core RUN apt update && \ apt install -y procps && \ curl -sSL https://aka.ms/getvsdbgsh | /bin/sh /dev/stdin -v latest -l /vsdbg WORKDIR /app # Copy csproj and restore as distinct layers COPY *.csproj ./ RUN