IdentityServer4 部署遇到的坑


Identityserver 實現token認證主要參考https://www.cnblogs.com/zhurunlai/p/10564508.html

這位博主的介紹很詳細,實際起服務時有個bug,報“invalid token”,原因是因為沒有定義scope,這個是必須自己配置的,默認的不可以

2.如果用.AddDeveloperSigningCredential(),服務會自動生成一個臨時的jwk文件,作為簽名文件,實際使用建議自己利用openssl生成配置文件,

可以參考https://www.cnblogs.com/fengchao1000/p/10254903.html

3.部署時用了nginx,本地授權路徑指向服務器路徑,但是從服務器獲取的token在本地unAuthrize,訪問configuration ,例如我服務的域名是http://example.com/Api,配置文件顯示的卻是http://localhost:5000,此時需要去修改nginx的

配置文件:

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;

重啟服務后配置文件路徑顯示http://example.com/.well-konwn.....,但是實際上我需要他顯示http://example.com/Api/.well-konwn.....,,原來可以用PublicOrigin,

但Identityserver4中沒有了,在StartUp中添加以下代碼解決

app.Use(async (ctx, next) =>//解決nginx配置問題
{
ctx.SetIdentityServerOrigin(“http://example.comj/Api”);
await next();
});


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM