首页 > 解决方案 > How should the options.authority be set when the api and the identity server are hosted on the same server

问题描述

I've got my web api (.net core web api) and my identity server 4 on the same IIS Windows Server. I've got the following code in my api with the authority set as below:

        services.AddAuthentication("Bearer")
        .AddJwtBearer("Bearer", options =>
        {
            options.Authority = https://identity.<domain name>.com;
            options.TokenValidationParameters = new TokenValidationParameters
            {
                ValidateAudience = false
            };
        });

I'm getting the following error when I communicate from my client to the api:

System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'https://identity..com/.well-known/openid-configuration'. ---> System.IO.IOException: IDX20804: Unable to retrieve document from: 'https://identity..com/.well-known/openid-configuration'. ---> System.Net.Http.HttpRequestException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

I believe the way I've set the Authority is causing the issue. Its trying to resolve itself to the same IP address and it times out. I've hosted my api on my development machine and called the same identity server and it works just fine. Should I make a change to the Hosts file or maybe find a base address (localhost or other) to resolve the communicate between the api and identity server?

标签: apiweb.net-coreidentityserver4

解决方案


推荐阅读