集成身份服务器; Docker和MVC Core(Web客户端) [英] Integrating Identity Server; Docker and MVC Core (Web Client)

查看:87
本文介绍了集成身份服务器; Docker和MVC Core(Web客户端)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使MVC Core Web应用程序与Identity Server和Docker一起使用.这是我已采取的步骤:

I am trying to get an MVC Core Web application to work with Identity Server and Docker. Here are the steps I have taken:

1)下载快速入门: https://github.com/IdentityServer/IdentityServer4.样本/树/开发

1) Download the quickstart: https://github.com/IdentityServer/IdentityServer4.Samples/tree/dev

运行该项目,并查看其是否按预期工作.现在尝试将Docker添加到公式中:

Run the project and see it working as expected. Now try adding Docker to the equation:

2)打开解决方案.右键单击:IdentityServerWithAspNetIdentity并选择:添加容器编排支持(然后是Docker Compose,然后是Linux). 3)右键单击MVCClient并选择:添加容器编排支持(然后是Docker Compose,然后是Linux). 4)将Docker-compose.override.yml更改为此(请注意,我仅将每个服务的端口从80更改为5002:80和5000:80):

2) Open the solution. Right click on: IdentityServerWithAspNetIdentity and select: Add Container Orchestration Support (Then Docker Compose, then Linux). 3) Right click on MVCClient and select: Add Container Orchestration Support (Then Docker Compose, then Linux). 4) Change Docker-compose.override.yml to this (note that I only changed the ports for each service from 80 to 5002:80 and 5000:80):

version: '3.4'

services:
  mvcclient:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    ports:
      - "5002:80"

  identityserverwithaspnetidentity:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    ports:
      - "5000:80"

5)尝试运行项目以查看会发生什么.当我尝试访问时:主页/安全;而不是转发到登录网页;我看到此错误:'Unable to obtain configuration from:http://localhost:5000/.well-known/openid-configuration'.

5) Try running the project to see what happens. When I attempt to access: Home/Secure; instead of being forwarded to the login webpage; I see this error: 'Unable to obtain configuration from:http://localhost:5000/.well-known/openid-configuration'.

我相信这是因为Docker容器无法看到localhost:5000.因此,在阅读了几篇博客文章之后;我尝试这个:

I believe this is because the Docker container cannot see localhost:5000. Therefore after reading through a few blog posts; I try this:

6)在MVCClient中打开启动并更改它:

6) Open startup in the MVCClient and change this:

options.Authority = "http://localhost:5000";

对此:

options.Authority = "http://identityserverwithaspnetidentity:80";

但是,我只看到一个DNS错误(我相信是404).在这种情况下,我需要怎么做才能使Identity Server与MVC Web应用程序一起使用?

However, I just see a DNS error (404 I believe). What do I need to do to get Identity Server working with an MVC web app in this case?

到目前为止,我一直在这里查看: Identity Server 4和docker .但是,到目前为止,答案仍无济于事.

So far I have looked here: How can I use IdentityServer4 from inside and outside a docker machine? and here: Identity Server 4 and docker. However the answers have not helped so far.

推荐答案

您在我的线程我遇到了类似的问题.我所做的是在IdentityServerAuthenticationOptions(API端)上配置以下内容:

As you already noticed on my thread I had a similar issue. What I did is configuring the following on my IdentityServerAuthenticationOptions (API Side):

1)设置正确的Autority,在您的情况下,我会说它应该是 http://identityserverwithaspnetidentity/
2)配置ApiName(这是ApiResource的名称)
3)也许还配置JwtBackChannelHandler(不确定是否需要)
4)如果您不使用Https,我将停用它(我不记得是否明确需要这样做:将RequireHttpsMetadata设置为false)

1) Set the correct Autority, in your case I would say it should be http://identityserverwithaspnetidentity/
2) Configure the ApiName (this is the name of the ApiResource)
3) Maybe also configure JwtBackChannelHandler (Im not sure if this was required or not)
4) If you are not using Https, I would deactivate it (I don't remember if this is explicitly needed: set RequireHttpsMetadata to false)

然后在客户端上我进行了跟踪

And on the client I did the folling

1)将ValidateIssuerName设置为false
2)如果您不使用Https,也许也可以通过将RequireHttps设置为false来停用它(我不记得是否明确需要这样做)

1) Set the ValidateIssuerName to false
2) If you are not using Https, maybe also deactive it by setting RequireHttps to false (I don't remember if this is explicitly needed)

这篇关于集成身份服务器; Docker和MVC Core(Web客户端)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆