クライアントの定義

クライアントは、IDサーバーからトークンを要求できるアプリケーションを表します。

詳細は異なりますが、通常はクライアントに対して以下の共通設定を定義します。

  • 一意のクライアントID
  • 必要なら秘密
  • トークンサービスとの許可された対話(許可タイプと呼ばれる)
  • アイデンティティおよび/またはアクセストークンが送信される(リダイレクトURIと呼ばれる)ネットワークロケーションは、
  • クライアントがアクセスできるスコープのリスト(別名リソース)

注釈

実行時に、クライアントは.htmlの実装を介して取得されますIClientStore。これにより、設定ファイルやデータベースなどの任意のデータソースから読み込むことができます。このドキュメントでは、クライアントストアのメモリ内バージョンを使用します。拡張メソッドを使用しConfigureServicesてインメモリストアを配線することができAddInMemoryClientsます。

サーバ間通信のためのクライアントの定義

このシナリオでは、対話ユーザーは存在しません。サービス(別名クライアント)はAPI(別名スコープ)と通信したいと考えています。

public class Clients
{
    public static IEnumerable<Client> Get()
    {
        return new List<Client>
        {
            new Client
            {
                ClientId = "service.client",
                ClientSecrets = { new Secret("secret".Sha256()) },

                AllowedGrantTypes = GrantTypes.ClientCredentials,
                AllowedScopes = { "api1", "api2.read_only" }
            }
        };
    }
}

ユーザ認証と委任されたアクセスとAPIのためのブラウザベースのJavaScriptクライアント(例えばSPA)の定義

このクライアントは、暗黙のフローを使用して、JavaScriptからIDとアクセストークンを要求します。

var jsClient = new Client
{
    ClientId = "js",
    ClientName = "JavaScript Client",
    ClientUri = "http://identityserver.io",

    AllowedGrantTypes = GrantTypes.Implicit,
    AllowAccessTokensViaBrowser = true,

    RedirectUris =           { "http://localhost:7017/index.html" },
    PostLogoutRedirectUris = { "http://localhost:7017/index.html" },
    AllowedCorsOrigins =     { "http://localhost:7017" },

    AllowedScopes =
    {
        IdentityServerConstants.StandardScopes.OpenId,
        IdentityServerConstants.StandardScopes.Profile,
        IdentityServerConstants.StandardScopes.Email,

        "api1", "api2.read_only"
    }
};

認証とデリゲートされたAPIアクセスを使用するためのサーバー側Webアプリケーション(MVCなど)の定義

対話型サーバー側(またはネイティブデスクトップ/モバイル)アプリケーションは、ハイブリッドフローを使用します。このフローは、アクセストークンがバックチャネルコールのみで送信されるため(バックプレーントークンにアクセスできるため)、最高のセキュリティを提供します。

var mvcClient = new Client
{
    ClientId = "mvc",
    ClientName = "MVC Client",
    ClientUri = "http://identityserver.io",

    AllowedGrantTypes = GrantTypes.Hybrid,
    AllowOfflineAccess = true,
    ClientSecrets = { new Secret("secret".Sha256()) },

    RedirectUris =           { "http://localhost:21402/signin-oidc" },
    PostLogoutRedirectUris = { "http://localhost:21402/" },
    FrontChannelLogoutUri =  "http://localhost:21402/signout-oidc",

    AllowedScopes =
    {
        IdentityServerConstants.StandardScopes.OpenId,
        IdentityServerConstants.StandardScopes.Profile,
        IdentityServerConstants.StandardScopes.Email,

        "api1", "api2.read_only"
    },
};