2017-06-19 1 views
0

私は.net webapiに対してidentityserver3を使用して認証を設定しようとしています。IdentityServer3 .Net Web API。エラーを取得しています - このリクエストで承認が拒否されました

これは、認証サーバープロジェクト

public class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
     // hardcoded list of clients, scopes and users 

     var factory = new IdentityServerServiceFactory() 
      .UseInMemoryClients(clients) 
      .UseInMemoryScopes(scopes) 
      .UseInMemoryUsers(users); 

     app.UseIdentityServer(new IdentityServerOptions 
     { 
      SigningCertificate = new X509Certificate2([email protected]"{AppDomain.CurrentDomain.BaseDirectory}\bin\my_selfsigned_cert.pfx", ConfigurationManager.AppSettings["certificatekey"]), 
      RequireSsl = false, 
      Factory = factory 
     }); 
    } 

のOwin.Startupで私のコードで、次が起動owin私のWeb APIのコード

public class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
     app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions 
     { 
      Authority = "http://localhost:45230" 
     }); 

     app.UseWebApi(GlobalConfiguration.Configuration); 
    } 
} 

マイ認証サーバは時に動作しているようですアイデンティティ・サーバーのログイン・ページにログインしようとしています。私はまた、/connect/token に投稿することで認証トークンを取得することができます。しかし、以下のように受け取ったベアラトークンを使用して私のwebapiメソッドを呼び出すと、常にエラー "{"メッセージ ":"この要求に対して承認が拒否されました。 }

アピ - ?

[HttpGet] 
    [Authorize] 
    public IEnumerable<Customer> Get() 
    { 
     var customerRepository = new CustomerRepository(); 
     return customerRepository.GetCustomers(); 
    } 

は、誰かが私が行方不明です何を提案してくださいすることができ

+0

おそらく間違いですが、アプリケーションのスコープを指定する必要はありませんか? – uk2k05

+1

[https://identityserver.github.io/Documentation/docsv2/overview/mvcGettingStarted.html](https://identityserver.github.io/Documentation/docsv2/overview/mvcGettingStarted.html)にはまともな画面グラブがあるようですStartup.csをセットアップして正しいスコープを作成する方法について – uk2k05

+0

スコープopenidが認証トークンを取得するために/ connect/tokenへの投稿を行っている間に認証サーバーに渡されました。また、使用可能なスコープの一覧は、メモリ内のコレクション(コードが提供されている)として認証サーバーに提供されます。画面グラブは、ログインページを使用する異なるフロー/グラントについて説明します。私の場合、私は私webapiを確保しており、関与するuiはありません。 – Anoop

答えて

0

Microsoft.Owin.Host.SystemWeb

hereで提案されているように、このナゲットをウェブAPIプロジェクトにインストールしました。

関連する問題