2017-02-22 22 views
0

Каков наилучший метод установки секретности Scope для 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" 
       } 
      } 
     } 
    }; 
}