私は立ち往生しています。Azure AD B2Cに対してOWIN/OIDCを使用してカスタムUmbracoコントローラを認証する
私はRenderMvcController
を継承するカスタムUmbracoコントローラを持っていますが、Index()
アクションメソッドがヒットした場合、ファイルが返されます。これはうまくいきますが、私がしたいのは、アクションをAuthorizeAttribute
で修飾し、ユーザーに認証を要求することで保護することです。
namespace MyNamespace.Controllers
{
public class MyModelController : RenderMvcController
{
[Authorize]
public ActionResult Index(RenderModel model)
{
// ...
}
}
}
認証は、Azure AD B2Cアプリケーションに対してOWINとOpenId Connectを使用して行われます。これもうまく動作し、テストされますが、Umbraco以外のコンテキストではテストされます。
私は主題に関連した多数のスレッドとコードを読んでいますが、私はUmbraco内に統合するのに苦労しています。私はUmbracoDefaultOwinStartup
から継承するカスタム起動クラスを持っています。 AuthController
へのカスタムルートを登録し、IAppBuilder.UseOpenIdConnectAuthentication()
でOIDCを設定します。
しかし、私はウンブラの接着剤が必要で、どのようにしてクッキーを設定すべきかを理解する上で問題があります。スタートアップのConfiguration()
メソッドが呼び出されたことを確認しました。
namespace MyNamespace
{
public class CustomOwinStartup : UmbracoDefaultOwinStartup
{
public override void Configuration(IAppBuilder app)
{
base.Configuration(app);
ConfigureAuth(app);
RouteTable.Routes.MapRoute(
"CustomAuth",
"CustomAuth/{action}",
new { controller = "Auth" }
);
}
private void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/CustomAuth/SignUpSignIn") // TODO: What should I put here?
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseOpenIdConnectAuthentication(
// Passing options that are tested and working
);
}
}
}
次に、当面は非常に簡単な認証コントローラがあります。 Umbracoユーザーと認証情報を同期する必要はありません。
namespace MyNamespace.Controllers
{
public partial class CustomAuthController : Controller
{
public CustomAuthController() : base()
{
}
public void SignUpSignIn()
{
if (!Request.IsAuthenticated)
{
HttpContext.GetOwinContext().Authentication.Challenge();
return;
}
Response.Redirect("/"); // TODO: Maybe this should redirect me back to original route MyModel/Index in some way
}
}
}
私はこれを実行すると、私の属性装飾カスタムUmbracoコントローラを介してにしようと、私はこのエラーを取得する:
Page not found
No umbraco document matches the url
'/login.aspx?ReturnUrl=MYORIGINALROUTEHTTPENCODED'
. This page can be replaced with a custom 404. Check the documentation for "custom 404".
私の推測では、これが原因Web.config
で<authentication mode="Forms">
設定であることですが、あれば私はこれを削除するか、属性mode
を"None"
に設定しましたが、これはバックオフィスのログインには影響しませんか?
誰かが私を正しい方向に向けるのを手伝ってもらえると非常に感謝しています!
[このサンプルアプリケーション](https://github.com/Azure-Samples/active-directory-b2c-dotnet-webapp-and-webapi/blob/master/TaskWebApp/App_Start/)を確認しましたか? Startup.Auth.cs)はowin w/b2cを使用していますか? – spottedmahn
はい、私はそれをOIDCコンフィギュレータに渡しているオプションオブジェクトの基礎としています。 – Viktor
詳しくは、サンプルアプリケーションを使用して作業するようにしましたが、今のまま残しておきたい既存のUmbracoアプリケーションに同じ認証レイヤーを追加したいと思います。 Umbracoのフロントエンドユーザーストアに接続するための私のカスタム認証は必要ありません。私はauth-then-forgetをしたいからです。または、auth-then-maybe-logを入力します。残りのサイトは公開されています。 – Viktor