Exemplo n.º 1
0
        public async Task AddClientAsync()
        {
            string              a       = "secret".Sha512();
            IClientService      service = Startup.CreateCluster().GrainFactory.GetGrain <IClientService>("@");
            ClientAddRequestDto dto     = new ClientAddRequestDto
            {
                ClientName  = "OTC客户端",
                ClientUri   = "https://otc1.zgzop.com",
                MerchantId  = "10000",
                Description = "OTC客户端",
                LoginUri    = "https://otc1.zgzop.com/login"
            };

            dto.AllowedGrantTypes.Add(GrantType.ClientCredentials);
            dto.AllowedScopes.Add("profile");
            dto.AllowedScopes.Add("phone");
            dto.AllowedScopes.Add("openid");
            dto.AllowedScopes.Add("UC_API");
            dto.AllowedScopes.Add("OTC_API");
            dto.AllowedScopes.Add("OT_API");
            var secret = new DTO.SecretDto("Gcyayx5tX2x12Vhp07BJuoAqXG8P4mUY", "OTC客户端-Gcyayx5tX2x12Vhp07BJuoAqXG8P4mUY", Convert.ToDateTime("2030-01-01 12:12:12"));

            dto.Secrets.Add(secret);
            var response = await service.AddAsync(dto);
        }
Exemplo n.º 2
0
        public async Task <ResultResponseDto> AddAsync(ClientAddRequestDto dto)
        {
            if (!dto.IsValid())
            {
                return(Result.ReFailure <ResultResponseDto>("请求参数错误", ResultCodes.InvalidParameter));
            }
            //生成
            string clientId = base.ServiceProvider.GetRequiredService <IIDGenerated>().NextId().ToString();
            Client client   = new Client(clientId, dto.MerchantId)
            {
                ClientName  = dto.ClientName,
                ClientUri   = dto.ClientUri,
                LogoUri     = dto.LogoUri,
                LoginUri    = dto.LoginUri,
                Description = dto.Description
            };
            var result = this.SetScopes(dto.AllowedScopes, client);

            if (!result.Success)
            {
                return(Result.ReFailure <ResultResponseDto>(result));
            }

            result = this.SetGrantTypes(dto.AllowedGrantTypes, client);
            if (!result.Success)
            {
                return(Result.ReFailure <ResultResponseDto>(result));
            }

            foreach (var item in dto.Secrets)
            {
                Secret secret = new Secret(item.Value, item.Type, item.Description, item.Expiration);
                if (!secret.IsValid())
                {
                    return(Result.ReFailure <ResultResponseDto>("秘钥请求参数错误", ResultCodes.InvalidParameter));
                }
                client.Secrets.Add(secret);
            }
            if (!client.IsValid())
            {
                return(Result.ReFailure <ResultResponseDto>("请求参数错误不合法", ResultCodes.InvalidParameter));
            }
            base.State = client;
            await base.WriteStateAsync();

            return(Result.ReSuccess <ResultResponseDto>());
        }