2017-02-22 3 views
0

Was ist die beste Methode, um das Scope-Geheimnis für eine ApiResource festzulegen? Ich habe in dieser Hinsicht viele Hinweise auf IdentityServer3 gefunden, aber keiner von ihnen überträgt sich auf das neue Release. Ein Codebeispiel wäre großartig. Ich bin mir ziemlich sicher, dass ich das nur falsch definiere, aber ich kann mein ganzes Leben lang nicht damit umgehen. Hier ist mein aktueller Code:Einstellung des IdentityServer4 Scope Secret

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") 
      }; 
     } 
    } 
} 

Was füge ich hinzu? Was nehme ich mit? Ich habe die Dokumente durch und durch gelesen und finde keine für mein Problem spezifische Instanz.

Antwort

0

die Antwort in einem übersehen Teil der docs hier gefunden: http://docs.identityserver.io/en/release/configuration/resources.html

-Code vollständig erscheint als

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" 
       } 
      } 
     } 
    }; 
} 
Verwandte Themen