我爲我的項目使用身份服務器3,我目前有一個網站和api被Id服務器保護,這是工作正常,但因爲我存儲用戶的身份證服務器數據庫我不能真正改變網站上的任何用戶數據,如更改個人資料圖片或任何聲明價值。身份服務器和用戶管理的網絡api
爲了解決這個問題,我正在考慮在IdServer上創建一個API,這個API會管理用戶,更改密碼,檢索用戶或者更改與用戶相關的任何東西,我想創建這個API在使用Owin映射的我的IdServer示例項目上。
現在,我有我的/身份路線idServer這樣
public class Startup
{
public void Configuration(IAppBuilder app)
{
Log.Logger = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.Trace().CreateLogger();
app.Map("/identity", idserverApp =>
{
var efConfig = new EntityFrameworkServiceOptions
{
ConnectionString = "IdSvr3Config"
};
var options = new IdentityServerOptions
{
SiteName = "Identity server",
IssuerUri = ConfigurationManager.AppSettings["idserver:stsIssuerUri"],
PublicOrigin = ConfigurationManager.AppSettings["idserver:stsOrigen"],
SigningCertificate = Certificate.Get(),
Factory = Factory.Configure(efConfig),
AuthenticationOptions = AuthOptions.Configure(app),
CspOptions = new CspOptions { Enabled = false },
EnableWelcomePage=false
};
new TokenCleanup(efConfig, 3600 * 6).Start();
idserverApp.UseIdentityServer(options);
});
app.UseIdServerApi();
}
}
我的API「中間件」是因爲這
**public static class IdServerApiExtensions
{
public static void UseIdServerApi(this IAppBuilder app, IdServerApiOptions options = null)
{
if (options == null)
options = new IdServerApiOptions();
if (options.RequireAuthentication)
{
var dic = app.Properties;
JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
app.UseIdentityServerBearerTokenAuthentication(
new IdentityServerBearerTokenAuthenticationOptions
{
Authority = "https://localhost:44302/identity", //here is the problem, it says not found even though I already mapped idServer to /identity
RequiredScopes = new[]
{
"idserver-api"
},
ValidationMode=ValidationMode.ValidationEndpoint
});
}
var config = new HttpConfiguration();
WebApiConfig.Register(config,options.RequireAuthentication);
app.UseNinjectMiddleware(() => NinjectConfig.CreateKernel.Value);
app.UseNinjectWebApi(config);
app.Use<IdServerApiMiddleware>(options);
}
}**
我知道可能我只是不知道在同一個項目上使用api是一個好主意,而且我也不知道如何去做。
- 創建這個API來管理用戶是一個好主意嗎?如果不是我可以使用什麼?
- 如何創建適當的設置來啓動/ api下的API並同時使用IdServer來保護此api?
更新
添加ValidationMode = ValidationMode.ValidationEndpoint,固定我的問題,這要歸功於斯科特·布雷迪
感謝
嗨斯科特,當你說一個項目你也意味着在另一個URL?我想有身份的服務器和API來在不同的路徑下,我添加了api,它在/ api下正常工作,但是如果我使用IdServer打開身份驗證,那麼它會停止工作,因爲我的猜測是Owin尚未加載導致權限的idserver端點失敗,有什麼想法? –
檢查我的問題,我添加了我爲api設置的代碼 –
您可以保持相同的URL(使用不同的路徑)只是保持代碼分離。如果這適用於您,可以將項目(思考VS解決方案)部署到IIS中同一網址上的不同路徑。在OWIN路徑中使用AccessTokenValidation中間件應該沒問題,如果它在啓動時失敗,那麼這聽起來像是一個單獨的問題/問題。我已經看到項目在同一個應用程序中使用Identity Server實現。它確實有效。 –