私は、認可/認証用のIdentityServer3 SSOサービスと、データおよびビジネスロジックへのアクセスを提供する.NET Core WebApiサービスレイヤーで動作するAngularJSシングルページアプリケーションを使用しています。リダイレクト間のセッション状態を管理する
通常、ユーザーがログインすると、アプリケーションはWebホームページにリダイレクトされます。しかし、状況によっては、別のURLに戻るためにアプリケーションが必要です。開発者によると、IdentityServer3 cannot do this、したがって、要件はアプリケーションで処理する必要があります。彼らはセッションストレージを使用して、アプリケーションが認証のためにSSOサイトにアクセスする前から、返されるまで、保存されたURLを取得してユーザーをユーザーにリダイレクトする前にリダイレクトURLを保持することを提案しています。
これを考慮して、私は、URLを永続化するWEBAPIコントローラを書いた:
[Route("api/[controller]")]
public class RedirectController : Controller
{
private const string _redirectKey = "RedirectUrl";
// GET: api/redirect
[HttpGet]
public string Get()
{
return HttpContext.Session.GetString(_redirectKey);
}
// POST api/redirect
[HttpPost()]
public void Post([FromBody]string url)
{
HttpContext.Session.SetString(_redirectKey, url);
}
// DELETE api/redirect/
[HttpDelete()]
public void Delete()
{
HttpContext.Session.Remove(_redirectKey);
}
}
とURLを設定し、取得するためのSPAのメソッド:
//to initiate authorisation
$scope.logIn = function() {
var url = $config.webRoot + "/#/myurl";
redirectService.setRedirectUrl(url).then(function (success) {
if (success) {
authorisationService.authorise();
}
});
};
//after authorisation
authorisationService.processTokenCallbackAsync(hash).then(function() {
//$log.info(authorisationService.accessToken());
//check if the app has set a redirect url for this session
redirectService.getRedirectUrl().then(function (url) {
$window.location.href = url || $config.webRoot + "/#/";
});
}, function (error) {
$log.error(error && error.message || error);
});
しかし、セッションがありますアプリがSSOサイトにナビゲートすると終了しました。戻ってくると、SessionIDが異なります。 SSOリダイレクトを介してセッション状態を持続させることは可能ですか?もしそうなら、私はどのようにしますか?
感謝はい、それは動作します。 –