---
title: "Sitecore Identityサーバーをフェデレーションゲートウェイとして使用してください"
slug: "use-the-sitecore-identity-server-as-a-federation-gateway"
abstract: "Sitecore Identityサーバーは外部のアイデンティティプロバイダーへのゲートウェイとして機能します。"
---
# Sitecore Identityサーバーをフェデレーションゲートウェイとして使用してください

[Duende IdentityServer](https://docs.duendesoftware.com/identityserver/v6)をベースにしているため、Sitecore Identity(SI)サーバーを1つ以上の外部アイデンティティプロバイダー(またはサブプロバイダー、時に*内部プロバイダー*とも呼ばれる)へのゲートウェイとして利用できます。[IdentityServer Federation Gateway](https://docs.duendesoftware.com/identityserver/v6/ui/login/external/)にはこの概念に関する詳細情報があります。

サブプロバイダーを設定すると、SIサーバーのログイン画面にそのプロバイダーのログインボタンが表示されます。

SIサーバーに含まれるAzure ADアイデンティティプロバイダーを有効にする必要があります。これを行う手順は {SI\_server\_root\_folder}\\sitecore\\Sitecore.Plugin.IdentityProvider.AzureAd\\Config\\readme.txtファイルをご覧ください。

> [!noteOpenID ConnectとAzure Active Directoryを使ってウェブアプリケーションへのアクセスを認可することで、Azure ADをSIサーバーと連携させることができます](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-protocols-oidc)

> !注もし「リクエストで指定された返信URLがアプリケーションに設定された返信URLと一致しない」というエラーを見た場合、アプリケーションマニフェストのreplyUrlsセクションでhttps://SI Server host name/signin-oidc URLを使用してください。

## Sitecore Identityサーバーでサブプロバイダーの設定

SIサーバーにサブプロバイダーを追加するには:

1.  Visual Studioで新しいプラグインを作成する:
    
    :::文字で
    
    1.  *Class Library*(.NET 8.0)C#プロジェクトを作成しましょう。
        
    2.  リポジトリのルートにglobal.jsonファイルを作成します:
        
        {
         "msbuild-sdks": {
         "Sitecore.Framework.Runtime.Build": "4.0.0"
         }
        }
        
        .NET 8プロジェクトにはバージョン4.0.0を使いましょう。
        
    3.  csprojファイルを編集して、Projectノードの後に<Sdk Name="Sitecore.Framework.Runtime.Build" />を追加します。
        
    4.  目標フレームワークをnet8.0に設定する:
        
        <TargetFramework>net8.0</TargetFramework>
        
    5.  他に必要な参考文献を追加してください:
        
        -   *Microsoft。AspNetCore.Authentication.OpenIdConnect* (バージョン8.0.10)でOpenID Connect認証を有効にするためのもの。
        -   *Sitecore。Framework.Runtime.Abstractions* (バージョン8.0.1)でランタイム抽象化の使用が可能になります。
        -   Sitecoreへの言及。アイデンティティプロバイダーのベースクラスが必要な場合は *Plugin.IdentityProviders* プロジェクトを使います。:::
2.  優先サブプロバイダーのサービスは、そのプロバイダーの指示に従って設定し、SignInScheme設定をidsrv.externalと指定します。
    
    > !注*AddOpenIdConnect*のような認証ミドルウェアを使用するには、*Microsoftを使用します。AspNetCore.Authentication.OpenIdConnect*パッケージ(バージョン8.0.10以降)。このパッケージは.NET 8.0と互換性があります。
    
    C#におけるConfigureSitecore.csの例構成:
    
    using Microsoft.AspNetCore.Authentication;  
    using Microsoft.Extensions.Configuration;  
    using Microsoft.Extensions.DependencyInjection;  
    using Microsoft.Extensions.Logging;  
    using Sitecore.Framework.Runtime.Configuration;    
    
    namespace Sitecore.Plugin.IdentityProvider.YourProvider  
    {     
     public class ConfigureSitecore
     {           
     private readonly ILogger<ConfigureSitecore> \_logger;           
     private readonly AppSettings \_appSettings;             
    
     public ConfigureSitecore(ISitecoreConfiguration scConfig, ILogger<ConfigureSitecore> logger)           
     {               
     \_logger = logger;               
     \_appSettings = new AppSettings();               
     scConfig.GetSection(AppSettings.SectionName).Bind(\_appSettings.YourProvider);           
     }             
    
     public void ConfigureServices(IServiceCollection services)           
     {               
     var provider = \_appSettings.YourProvider;                 
    
     if (!provider.Enabled)               
     {                   
     return;               
     }                 
    
     \_logger.LogDebug($"Configure '{provider.DisplayName}'. AuthenticationScheme = {provider.AuthenticationScheme}");
    
                new AuthenticationBuilder(services)                   
     .AddOpenIdConnect(provider.AuthenticationScheme, provider.DisplayName, options =>                   
     {                       
     options.SignInScheme = "idsrv.external";                       
     options.Authority = provider.Authority;                       
     options.ClientId = provider.ClientId;                       
     options.ClientSecret = provider.ClientSecret;                       
     options.ResponseType = "code";                       
     options.SaveTokens = true;                                              
    
     options.Scope.Clear();                       
     options.Scope.Add("openid");                       
     options.Scope.Add("profile");                       
     options.Scope.Add("email");                   
     });           
     }       
     }  
    }
    
3.  構成にサブプロバイダーを登録してください。 {SI\_server\_root\_folder}\\sitecore\\Sitecore.Plugin.IdentityProvider.AzureAd\\Config\\Sitecore.Plugin.IdentityProvider.AzureAd.xmlファイルにはその例があります。
    
    例設定XML
    
    <?xml version="1.0" encoding="utf-8"?>
    <Settings>
     <Sitecore>
     <ExternalIdentityProviders>
     <IdentityProviders>
     <YourProvider type="Sitecore.Plugin.IdentityProviders.IdentityProvider, Sitecore.Plugin.IdentityProviders">
     <AuthenticationScheme>IdS4-YourProvider</AuthenticationScheme>
     <DisplayName>Your Provider Name</DisplayName>
     <Enabled>true</Enabled>
     <Authority>https://your-provider.com</Authority>
     <ClaimsTransformations>
     <!-- Claims transformation rules here -->
     </ClaimsTransformations>
     </YourProvider>
     </IdentityProviders>
     </ExternalIdentityProviders>
     </Sitecore>
    </Settings>
    
4.  オプションとして、Sitecoreインスタンスにサブプロバイダーを登録することもできます。
    

## Sitecoreインスタンスにサブプロバイダーを登録する

Sitecoreインスタンスのsitecore:federatedAuthentication:identityProviders設定ノードでサブプロバイダーを登録できます。 {application\_root\_folder}\\App\_Config\\Sitecore\\Owin.Authentication.IdentityServer\\Sitecore.Owin.Authentication.IdentityServer.configファイルにはその例があります。

XMLの例

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
 <sitecore>
 <federatedAuthentication>
 <identityProviders>
 <identityProvider id="YourProvider" type="Sitecore.Owin.Authentication.Configuration.DefaultIdentityProvider, Sitecore.Owin.Authentication">
 <param desc="name">$(id)</param>
 <param desc="domainManager" type="Sitecore.Abstractions.BaseDomainManager" resolve="true" />
 <caption>Your Provider Name</caption>
 <domain>extranet</domain>
 <transformations hint="list:AddTransformation">
 <transformation name="Name Transformation" type="Sitecore.Owin.Authentication.Services.DefaultTransformation, Sitecore.Owin.Authentication">
 <sources hint="raw:AddSource">
 <claim name="name" />
 </sources>
 <targets hint="raw:AddTarget">
 <claim name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name" />
 </targets>
 <keepSource>true</keepSource>
 </transformation>
 </transformations>
 </identityProvider>
 </identityProviders>
 </federatedAuthentication>
 </sitecore>
</configuration>

## クレーム変換の設定

各外部アイデンティティプロバイダーごとにクレーム変換を設定することができます。これらはSitecoreが既に持っているものに似ていますが、外部アイデンティティプロバイダーがSitecore Identity Serverクライアントで外部クレームを使用できるようにするには、SIサーバー側でクレーム変換が必要です。

デフォルトでは、Sitecore Identityは以下のカスタムスコープで動作します:アイデンティティリソースとしてのsitecore.profileとAPIリソースとしてのsitecore.profile.apiです。

sitecore.profileおよびsitecore.profile.apiのスコープには、以下の請求項が含まれています。

-   name
-   email
-   role
-   http://www.sitecore.net/identity/claims/isAdmin

ユーザーに役割を与えるために:

-   特定の入ってくるクレームを適切なロールクレームにマッピングします。例えば、90e5a2e5-4e3f-4f25-8beb-1238052fda8e Azure ADグループをsitecore\\Authorの役割に変換する場合:
    
    <AzureGroupTransformation type="Sitecore.Plugin.IdentityProviders.DefaultClaimsTransformation, Sitecore.Plugin.IdentityProviders">
     <SourceClaims>
     <Claim1 type="groups" value="90e5a2e5-4e3f-4f25-8beb-1238052fda8e" />
     </SourceClaims>
     <NewClaims>
     <Claim1 type="role" value="sitecore\\Author" />
     </NewClaims>
    </AzureGroupTransformation>
    

ユーザーを管理者にするには:

-   http://www.sitecore.net/identity/claims/isAdminを加え、値をtrueに設定します(Sitecoreの管理者ユーザーであることは特定の役割を持つことではありません)。例えば、a9bb60b6-40d2-4e2a-88b8-0e47ee2d078e Azure ADグループのすべてのユーザーを管理者ユーザー Sitecore作成する場合:
    
    <AzureADUserToAdminUser type="Sitecore.Plugin.IdentityProviders.DefaultClaimsTransformation, Sitecore.Plugin.IdentityProviders">
     <SourceClaims>
     <Claim1 type="groups" value="a9bb60b6-40d2-4e2a-88b8-0e47ee2d078e" />
     </SourceClaims>
     <NewClaims>
     <Claim1 type="http://www.sitecore.net/identity/claims/isAdmin" value="true"/>
     </NewClaims>
    </AzureADUserToAdminUser>
    

次に、configuration:sitecore:federatedAuthentication:propertyInitializer:mapsノードのSitecoreに請求を写像します。{application\_root\_folder}\\App\_Config\\Sitecore\\Owin.Authentication.IdentityServer\\Sitecore.Owin.Authentication.IdentityServer.config fileにはその例があります:

<federatedAuthentication>
 <propertyInitializer>
 <maps>
 <map name="email" to="Email" />
 <map name="name" to="FullName" />
 <map name="http://www.sitecore.net/identity/claims/isAdmin" to="IsAdministrator" />
 </maps>
 </propertyInitializer>
</federatedAuthentication>

変換された名前とメールの請求も同様の手順で、Sitecoreのユーザープロパティにマッピングしてください。

以下の例は、必須の請求項変換の必要性を示しています。

サブプロバイダーがhttp://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress請求を含むIDを返した場合、どのSIクライアントでも取得できません。選択肢は2つあります:

-   http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress請求をSIサーバー側でemail変換し、SIサーバークライアントがemail請求を受け取るようにします。
    
    <ClaimsTransformation type="Sitecore.Plugin.IdentityProviders.DefaultClaimsTransformation, Sitecore.Plugin.IdentityProviders">
     <SourceClaims>
     <Claim1 type="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" />
     </SourceClaims>
     <NewClaims>
     <Claim1 type="email" />
     </NewClaims>
    </ClaimsTransformation>
    
-   すべてのSIクライアントでhttp://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddressの主張をemailに変えましょう。
    

Sitecoreが外部ユーザーを表す永続ユーザーを作成する際には、いくつかの制限があります。Sitecoreはそのようなユーザーに対して以下の機能をサポートしていません。

1.  Sitecoreを通じたパスワード管理
2.  特定のプロファイル特性の変更
3.  ユーザーパスワードの変更。対応するアイデンティティプロバイダーでパスワードを変更しなければなりません。

## Configure Azure AD

Sitecore IdentityサーバーでAzure ADを設定・使用する際には、以下のことを覚えておく必要があります:

-   ウェブのアプリケーション登録の「**認証**」タブの詳細設定で**IDトークンの**チェックボックスを確認してください。
-   アプリケーションマニフェストで groupMembershipClaims 設定の値を ApplicationGroupに設定します。
-   replyUrls設定はレガシー版のアプリケーション登録のみです。代わりにreplyUrlsWithTypeを使いましょう。