i'm trying to access to user roles and guid contains in JTW provided by Azure AD with this code :
in ConfigureService
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddMicrosoftIdentityWebApi(Configuration.GetSection("AzureAd"));
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
in my controller i have those functions
private Guid getUserGuid()
{
var httpContext = _HttpContextAccessor.HttpContext;
var guid = httpContext.User.FindFirstValue("http://schemas.microsoft.com/identity/claims/objectidentifier");
return guid == null ? new Guid() : Guid.Parse(guid);
}
public Result GetUserInformations()
{
try
{
//Get user GUID
Guid guid = getUserGuid();
var httpContext = _HttpContextAccessor.HttpContext;
string[] roles = httpContext.User.Claims.Where(c => c.Type == ClaimTypes.Role).Select(c => c.Value).ToArray();
return new Result() { Success = true, Object = new UserInformations() { Guid = guid, Roles = roles} };
}
catch (Exception e)
{
return new Result() { Success = false, Message = $"{e.Message} {e.InnerException}" }; ;
}
}
Now i hosted my app on IIS 10 and i have this log :
fail: Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[3] Exception occurred while processing message. System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'System.String'. at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel) at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync() fail: Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[3] Exception occurred while processing message. System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'System.String'. ---> System.IO.IOException: IDX20804: Unable to retrieve document from: 'System.String'. ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.. ---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.
This work on my VS2022 and my personnal IIS10...
Any ideas
Thanks