2017-06-17 8 views
1

誰でも次の非常にイライラする問題を手伝ってくれることを願っています。AllowInsecureHttp = falseのトークンエンドポイントがまだhttpリクエストを受け付けています

私はjwt認証で保護した.NET WebApiを持っています。 OAuthAuthorizationServerOptionsのオブジェクトを設定する際に、私のトークンの終点のプロパティーAllowInsecureHttpfalseに設定しました。私の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) 
      } 
     }); 
    } 

} 

変数allowInsecureHttpissuersecretclientsは、構成ファイルから充填されています。 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を強制したいのです。

乾杯、これまでと同じ問題に遭遇した人のため ナイキスト

答えて

0

。最終的にそれを考え出す。チャームのように働いていましたが、仮想アプリケーションを設定したドメインのHSTSポリシーは、http Postmanのすべてのトラフィックを自動的にhttpsにリダイレクトしました。 SSLを使用しない単純なドメインにアプリケーションをインストールし、そのドメインにSSLを完全に適用しました。 sigh :)

関連する問題