private string GetClientSecretFromJson(string json, string clientId)
        {
            var config = LoadConfig(json);

            var source       = new ConfigurationBasedClientSource(NullLogger.Instance);
            var clientSecret = source.GetClientSecret(config.GetSection("Identity:Clients"), clientId);

            return(clientSecret);
        }
コード例 #2
0
        private static void ConfigureIdentityPlayerMangementClient(
            IServiceCollection services,
            IConfiguration configuration,
            ILogger logger)
        {
            if (configuration.Exists("Identity:PlayerManagementClient:wellKnown"))
            {
                // register using well-known type
                var wellKnownType       = configuration["Identity:PlayerManagementClient:wellknown"];
                var scopedConfiguration = configuration.GetSection("Identity:PlayerManagementClient:properties");
                switch (wellKnownType)
                {
                case "default":
                    var identityBaseUri = scopedConfiguration["IdentityBaseUrl"];
                    var apiBaseUri      = scopedConfiguration["ApiBaseUrl"];
                    logger.LogInformation("Identity:PlayerManagementClient: using 'default' client with IdentityBaseUrl '{0}', ApiBaseUrl '{1}'", identityBaseUri, apiBaseUri);

                    // could simplify this by requiring the client secret in the properties for PlayerManagementClient, but that duplicates config
                    var clientSource = new ConfigurationBasedClientSource(logger);
                    var clientSecret = clientSource.GetClientSecret(configuration.GetSection("Identity:Clients"), "nether_identity");
                    if (string.IsNullOrEmpty(clientSecret))
                    {
                        throw new Exception("Unable to determine the client secret for nether_identity");
                    }

                    services.AddSingleton <IIdentityPlayerManagementClient, DefaultIdentityPlayerManagementClient>(serviceProvider =>
                    {
                        return(new DefaultIdentityPlayerManagementClient(
                                   identityBaseUri,
                                   apiBaseUri,
                                   clientSecret,
                                   serviceProvider.GetRequiredService <ILogger <DefaultIdentityPlayerManagementClient> >()
                                   ));
                    });
                    break;

                default:
                    throw new Exception($"Unhandled 'wellKnown' type for Identity:PlayerManagementClient: '{wellKnownType}'");
                }
            }
            else
            {
                // fall back to generic "factory"/"implementation" configuration
                services.AddServiceFromConfiguration <IUserStore>(configuration, logger, "Identity:PlayerManagementClient");
            }
        }