基本認証を使用する ServiceStack API を構築しています。現在、次のように AppHost で認証を設定しています。
var authDb = new OrmLiteConnectionFactory("Server=(...);", true, MySqlDialectProvider.Instance);
var authRepo = new OrmLiteAuthRepository(authDb);
authRepo.CreateMissingTables();
container.Register<ICacheClient>(c => new MemoryCacheClient());
container.Register<IUserAuthRepository>(c => authRepo);
Plugins.Add(
new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] { new BasicAuthProvider() })
);
Authorization ヘッダーがないか、ユーザー名とパスが間違っている要求を実行すると、応答は /Account/Login.aspx?ReturnUrl=... へのリダイレクトになります。
部分的なリクエスト + レスポンスの例:
POST http://localhost:60278/reserve HTTP/1.1
HTTP/1.1 302 Found
Location: /Account/Login.aspx?ReturnUrl=%2freserve
X-Powered-By: ServiceStack/3,924 Win32NT/.NET
HTTP 401 Unauthorized または HTTP 403 Forbidden のみで応答させる方法はありますか?