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();
});