2016-07-07 12 views
3

私のプロジェクトにIdentity Server3を使用していますが、現在IDサーバーによって保護されているWebサイトとAPIがありますが、Idにユーザーを格納しているためサーバーのデータベース私は本当にプロファイルの写真やクレームの値を変更するようなWebサイトからユーザーのデータを変更することはできません。ユーザー管理のためのIdentity ServerとWeb API

これを解決するには、IdServerの上にAPIを作成することを考えています。このAPIはユーザーを管理し、パスワードを変更したり、ユーザーを取得したり、ユーザーに関連するものを変更したりします。 Owinマッピングを使用している私のIdServerを持っているサンプルプロジェクトで。

は今、私は次のように/アイデンティティルートでの私のidServerを持っているこの

public class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 

     Log.Logger = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.Trace().CreateLogger();    

     app.Map("/identity", idserverApp => 
     { 
      var efConfig = new EntityFrameworkServiceOptions 
      { 
       ConnectionString = "IdSvr3Config" 
      }; 

      var options = new IdentityServerOptions 
      { 
       SiteName = "Identity server", 
       IssuerUri = ConfigurationManager.AppSettings["idserver:stsIssuerUri"], 
       PublicOrigin = ConfigurationManager.AppSettings["idserver:stsOrigen"], 
       SigningCertificate = Certificate.Get(), 
       Factory = Factory.Configure(efConfig), 
       AuthenticationOptions = AuthOptions.Configure(app), 
       CspOptions = new CspOptions { Enabled = false }, 
       EnableWelcomePage=false 
      }; 


      new TokenCleanup(efConfig, 3600 * 6).Start(); 
      idserverApp.UseIdentityServer(options); 
     }); 

     app.UseIdServerApi(); 

    }   
} 

マイAPI「ミドルウェアは、」私が知っているこの

**public static class IdServerApiExtensions 
    { 
     public static void UseIdServerApi(this IAppBuilder app, IdServerApiOptions options = null) 
     { 
      if (options == null) 
       options = new IdServerApiOptions();    

      if (options.RequireAuthentication) 
      { 
       var dic = app.Properties; 
       JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>(); 
       app.UseIdentityServerBearerTokenAuthentication(
        new IdentityServerBearerTokenAuthenticationOptions 
        { 
         Authority = "https://localhost:44302/identity", //here is the problem, it says not found even though I already mapped idServer to /identity 
         RequiredScopes = new[] 
         { 
         "idserver-api" 
         }, 
         ValidationMode=ValidationMode.ValidationEndpoint 
        }); 
      } 
      var config = new HttpConfiguration(); 
      WebApiConfig.Register(config,options.RequireAuthentication); 
      app.UseNinjectMiddleware(() => NinjectConfig.CreateKernel.Value); 
      app.UseNinjectWebApi(config); 
      app.Use<IdServerApiMiddleware>(options); 
     } 
    }** 

が可能であるように私はちょうどかどうかを知りませんです同じプロジェクトにapiを持っているかどうかは分かりませんが、私はそれを行う方法もわかりません。

  • ユーザーを管理するためにこのAPIを作成することをお勧めしますか?もし私が何を使うことができないのであれば?
  • どのようにして/ apiの下でAPIを起動し、同時にこのAPIを保護するためにIdServerを使用するように適切な設定を作成できますか? ValidationMode = ValidationMode.ValidationEndpointを追加

更新

、Identity Serverのチームのスコット・ブレイディのおかげ

おかげ

答えて

6

一般的なアドバイスを実行することです、私の問題を修正任意の管理ページまたはAPIを別のプロジェクトとして使用します(Most recent example)。ベストプラクティスは、Identity ServerとID管理アプリケーションにIDデータベース/ストアへのアクセス権を与えることだけです。

ユーザーを管理するには、独自のAPIを作成することができます。他のオプションは、単一のMVC Webサイトに含めるか、Identity Managerのようなものを使用することです。

ただし、OWINマップを使用しても同じアプリケーションアプローチを使用できます。あなたはまた、別のURLに持っている別のプロジェクトを意味しますか?私は、アイデンティティ・サーバーおよびAPIにがしたいと言ったときに

app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions 
{ 
    Authority = ConfigurationManager.AppSettings["idserver:stsOrigen"], 
    RequiredScopes = new[] { "adminApi" }, 
    ValidationMode = ValidationMode.ValidationEndpoint 
}); 
+0

こんにちはスコット:これを確保するには、次のようなコードを使用して、IdentityServer3.AccessTokenValidationパッケージを使用することができます私はapiを追加しましたが、/ apiの下で動作していますが、IdServerを使用して認証をオンにすると、Owinがまだ権限を引き起こしているidserverエンドポイントが失敗する、任意のアイデア? –

+0

私の質問をチェックして、私はAPI設定のコードを追加しました –

+0

別のパスを使用して同じURLを保つことができます。これがあなたに当てはまる場合、IISの同じURL上の異なるパスにプロジェクト(VSソリューションと考える)を展開することができます。 OWINパスでAccessTokenValidationミドルウェアを使用することは問題ありません。起動時に失敗する場合は、別の問題/質問のように聞こえます。私は以前のプロジェクトと同じアプリケーションでIdentity Serverの実装をプロジェクトで使用していることがわかりました。それは動作します。 –

関連する問題