我正在嘗試獲取IdentityServer4的隱式流。登錄和註銷工作正常,但是PostLogoutRedirectUri會返回null,儘管設置了需要設置的值。我希望註銷過程在註銷完成後重定向回我的應用程序。IdentityServer4 PostLogoutRedirectUri null
我正確地得到logoutId,並註銷調用BuildLoggedOutViewModelAsync:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Logout(LogoutInputModel model)
{
var vm = await _account.BuildLoggedOutViewModelAsync(model.LogoutId);
...
這種方法位於我AccountService.cs類,然後調用DefaultIdentityServiceInteractionService的GetLogoutContextAsync:
public async Task<LoggedOutViewModel> BuildLoggedOutViewModelAsync(string logoutId)
{
// get context information (client name, post logout redirect URI and iframe for federated signout)
var logout = await _interaction.GetLogoutContextAsync(logoutId);
...
它創建一個IdentityServer4.Models.LogoutRequest。
SignOutIFrameUrl
字符串屬性設置爲"http://localhost:5000/connect/endsession/callback?sid=bf112f7785bc860fcc4351893012622e&logoutId=d6649e7f818d9709b2c0bc659696abdf"
,但LogoutRequest中似乎沒有填充任何其他內容。
不幸的是,這意味着PostLogoutRedirectUri
爲null並且AutomaticRedirectAfterSignOut
也爲空,並在裝入LoggedOut.cshtml
頁面時,永遠不會加載signout-callback.js
文件:
@section scripts
{
@if (Model.AutomaticRedirectAfterSignOut)
{
<script src="~/js/signout-redirect.js"></script>
}
}
這裏是我的配置設置。
Config.cs:
public static IEnumerable<Client> GetClients()
{
return new List<Client>
{
new Client
{
ClientId = "implicit.client",
AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true,
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"ContractManagerAPI"
},
RedirectUris = { "http://localhost:9000/" },
PostLogoutRedirectUris = { "http://localhost:9000/" },
AllowedCorsOrigins = { "http://localhost:9000" },
RequireConsent = false,
}
};
}
app.ts(JS客戶端):
import {UserManager} from 'oidc-client';
import { inject, Factory } from 'aurelia-framework';
@inject(Factory.of(UserManager))
export class App {
userManager: UserManager;
constructor(userManagerFactory){
let config = {
authority: 'http://localhost:5000',
client_id: 'implicit.client',
response_type: 'id_token token',
scope: 'openid profile ContractManagerAPI',
redirect_uri: 'http://localhost:9000/',
post_logout_redirect_uri: 'http://localhost:9000/'
};
this.userManager = userManagerFactory(config);
}
login(){
this.userManager.signinRedirect();
}
logout(){
this.userManager.signoutRedirect();
}
}
Startup.cs的相關部分:
services.AddIdentityServer()
.AddTemporarySigningCredential()
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients())
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddContractManagerUserStore()
.AddProfileService<ContractManagerProfileService>();
搞清楚其中的任何援助我會錯誤的將不勝感激。
謝謝!
喜@ JayDeeEss,我嘗試添加LogoutUrl到IdentityServer,但沒有運氣。我沒有MVC客戶端,它是一個JavaScript客戶端。我使用的是oidc-client.js文件,從我可以告訴的是沒有logout_url屬性。 – user2921364
Hi @ user2921364!我創建了角度客戶端(隱式流)與您的配置和它的工作正常。我唯一能想到的就是確保在服務下的AccountOptions.cs中將「AutomaticRedirectAfterSignout」選項設置爲true。這是我的AccountOptions類的樣子:(請查看上面的答案) – JayDeeEss
嗨@JayDeeEss,感謝您對此的支持。事實證明,它不那麼直觀。我使用了新的Oidc.UserManager()。signRedirectCallback()。then ...'腳本,它位於index.html頁面上。我決定按照'T'的指示並將其移至自己的callback.html頁面。一旦我做到了,一切都開始奏效。最大的線索是'userManager.getUser()'總是返回null,即使登錄了。我意識到登錄過程中缺少一些東西。 – user2921364