2017-02-22 74 views
0

設置ApiResource的範圍祕密的最佳方法是什麼?在這方面,我發現了很多IdentityServer3的引用,但沒有一個引用到新版本。一個代碼示例會很棒。我很確定我只是定義了這個錯誤,但不能在我的生活中纏住我的頭。這是我現在的代碼:IdentityServer4設置範圍祕密

using IdentityServer4.Models; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Threading.Tasks; 

namespace SomeProgram.Configurations 
{ 
    public class Scopes 
    { 
     public static IEnumerable<ApiResource> GetApiResources() 
     { 
      return new List<ApiResource> 
      { 
       new ApiResource("MyAPI", "My API") 
      }; 
     } 
    } 
} 

我該怎麼補充?我拿走了什麼?我已經閱讀了文檔,並且無法找到特定於我的問題的實例。

回答

0

找到答案在這裏文檔的忽視部分:http://docs.identityserver.io/en/release/configuration/resources.html

代碼全部顯示爲

public static IEnumerable<ApiResource> GetApis() 
{ 
    return new[] 
    { 
     // simple API with a single scope (in this case the scope name is the same as the api name) 
     new ApiResource("api1", "Some API 1"), 

     // expanded version if more control is needed 
     new ApiResource 
     { 
      Name = "api2", 

      // secret for using introspection endpoint 
      ApiSecrets = 
      { 
       new Secret("secret".Sha256()) 
      }, 

      // include the following using claims in access token (in addition to subject id) 
      UserClaims = { JwtClaimTypes.Name, JwtClaimTypes.Email } 
      }, 

      // this API defines two scopes 
      Scopes = 
      { 
       new Scope() 
       { 
        Name = "api2.full_access", 
        DisplayName = "Full access to API 2", 
       }, 
       new Scope 
       { 
        Name = "api2.read_only", 
        DisplayName = "Read only access to API 2" 
       } 
      } 
     } 
    }; 
}