誰でも次の非常にイライラする問題を手伝ってくれることを願っています。AllowInsecureHttp = falseのトークンエンドポイントがまだhttpリクエストを受け付けています
私はjwt認証で保護した.NET WebApiを持っています。 OAuthAuthorizationServerOptions
のオブジェクトを設定する際に、私のトークンの終点のプロパティーAllowInsecureHttp
をfalse
に設定しました。私のAPIをIISExpressでローカルに実行し、Postmanでテストするのは魅力的です。プロパティをtrue
に設定し、私のエンドポイントでトークンを要求すると、それをfalse
に設定すると、期待通りに404
が得られます。しかし、プロダクション環境(Windows 2012/IIS8)にAPIを公開し、プロパティをfalse
に設定すると、https と httpの両方でトークンを取得できます。ただ、その物件を聞いているようではありません。
私は、1つのhttpsバインディングだけのドメインの下で別名Apiを持つアプリケーションとしてAPIを実行します。私は私のAPIのために、次のヘルパー基本クラスを使用します。
public class BaseWebApi<TDerivedOAuthProvider> where TDerivedOAuthProvider : BaseOAuthProvider, new()
{
public BaseWebApi(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(DefaultAuthenticationTypes.ExternalBearer));
ConfigureOAuth(app);
WebApiConfig.Register(config);
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
app.UseWebApi(config);
}
private static void ConfigureOAuth(IAppBuilder app)
{
var allowInsecureHttp = Convert.ToBoolean(ConfigurationManager.AppSettings["jwt::allowInsecureHttp"].ToString());
var issuer = ConfigurationManager.AppSettings["jwt::issuer"].ToString();
var secret = TextEncodings.Base64Url.Decode(ConfigurationManager.AppSettings["jwt::secret"].ToString());
var clients = ConfigurationManager.AppSettings["jwt::clients"].ToString().Split(new char[] { ',' });
OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
{
AllowInsecureHttp = allowInsecureHttp,
AuthenticationType = DefaultAuthenticationTypes.ExternalBearer,
TokenEndpointPath = new PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(10),
Provider = new TDerivedOAuthProvider(),
RefreshTokenProvider = new BaseRefreshTokenProvider(),
AccessTokenFormat = new BaseJwtFormat(issuer),
};
// OAuth 2.0 Bearer Access Token Generation
app.UseOAuthAuthorizationServer(OAuthServerOptions);
// Api controllers with an [Authorize] attribute will be validated with JWT
app.UseJwtBearerAuthentication(new JwtBearerAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ExternalBearer,
AuthenticationMode = AuthenticationMode.Active,
AllowedAudiences = clients,
IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[]
{
new SymmetricKeyIssuerSecurityTokenProvider(issuer, secret)
}
});
}
}
変数allowInsecureHttp
、issuer
、secret
とclients
は、構成ファイルから充填されています。 allowInsecureHttp
の値をfalse
またはtrue
にハードコードしても、何も変更されません。この基本クラスは、その後も、この特定のAPIをチェックする資格の実際の実装を扱うCustomOAuthProvider
クラスを提供します(次の実際のAPI関数への)私の実際のAPIによってインスタンス化されます。
[assembly: OwinStartup(typeof(MyCustomAPI.Startup))]
namespace MyCustomAPI.API
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
BaseWebApi<CustomOAuthProvider> webApi = new BaseWebApi<CustomOAuthProvider>(app);
}
}
}
ホープ誰もが私を指すことができます正しい方向。この問題を脇に置くと、API自体が完璧に動作していますが、実際にはプロダクショントークンにSSLを強制したいのです。
乾杯、これまでと同じ問題に遭遇した人のため ナイキスト