public async Task <ActionResult> Test1()
        {
            OAuthClientStore oAuthClientStore = ServiceProvider.GetService <OAuthClientStore>();
            OperationResult  result           = null;
            //ClientInputDto clientDto = new ClientInputDto()
            //{
            //    Name = "测试客户端01",
            //    ClientType = ClientType.Application,
            //    Url = "http://localhost:10240",
            //    LogoUrl = "http://localhost:10240",
            //    RedirectUrl = "http://localhost:10240"
            //};
            //result = await clientStore.AddClient(clientDto);
            OAuthClientSecretInputDto secretDto = new OAuthClientSecretInputDto()
            {
                Type     = "Test Type",
                Remark   = "Remark",
                ClientId = 2
            };

            result = await oAuthClientStore.CreateClientSecret(secretDto);

            return(Content(result.Message));
        }
Beispiel #2
0
 public async Task<ActionResult> Test1()
 {
     OAuthClientStore oAuthClientStore = ServiceProvider.GetService<OAuthClientStore>();
     OperationResult result = null;
     //ClientInputDto clientDto = new ClientInputDto()
     //{
     //    Name = "测试客户端01",
     //    ClientType = ClientType.Application,
     //    Url = "http://localhost:10240",
     //    LogoUrl = "http://localhost:10240",
     //    RedirectUrl = "http://localhost:10240"
     //};
     //result = await clientStore.AddClient(clientDto);
     OAuthClientSecretInputDto secretDto = new OAuthClientSecretInputDto()
     {
         Type = "Test Type",
         Remark = "Remark",
         ClientId = 2
     };
     result = await oAuthClientStore.CreateClientSecret(secretDto);
     return Content(result.Message);
 }
Beispiel #3
0
        public async Task <IHttpActionResult> Login(LoginInfo loginInfo)
        {
            Logger.Info("{0}开始登陆", loginInfo.UserName);
            var result = await IdentityContract.Login(loginInfo, false);

            OperationResult createClientResult       = new OperationResult();
            OperationResult createClientSecretResult = new OperationResult();

            if (result.Successed)
            {
                OAuthClientStore             oAuthClientStore             = ServiceProvider.GetService <OAuthClientStore>();
                OAuthClientRefreshTokenStore oAuthClientRefreshTokenStore = ServiceProvider.GetService <OAuthClientRefreshTokenStore>();
                OAuthClient         oAuthClient = new OAuthClient();
                OAuthClientInputDto clientDto   = new OAuthClientInputDto()
                {
                    Name            = loginInfo.UserName,
                    OAuthClientType = OAuthClientType.Application,
                    Url             = "http://localhost:13800/",
                    LogoUrl         = "http://localhost:13800/",
                    RedirectUrl     = "http://localhost:13800/"
                };
                try
                {
                    createClientResult = await oAuthClientStore.CreateClient(clientDto);
                }
                catch (Exception ex)
                {
                    Logger.Error("CreateClient错误:" + ex.ToString());
                }
                if (createClientResult.Successed)
                {
                    oAuthClient = oAuthClientStore.GetOAuthClient(clientDto);
                    OAuthClientSecretInputDto secretDto = new OAuthClientSecretInputDto()
                    {
                        Type     = "Test Type",
                        Remark   = "Remark",
                        ClientId = oAuthClient.Id,
                    };
                    try
                    {
                        createClientSecretResult = await oAuthClientStore.CreateClientSecret(secretDto);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("CreateClientSecret错误:" + ex.ToString());
                    }

                    if (createClientSecretResult.Successed)
                    {
                        OAuthClientSecret   oAuthClientSecret = ClientSecretRepository.Entities.Where(x => x.Client.Id == oAuthClient.Id).FirstOrDefault();
                        ClientAndSecretData data = new ClientAndSecretData();
                        data.ClientId     = oAuthClient.ClientId;
                        data.ClientSecret = oAuthClientSecret.Value;
                        result.Message    = JsonHelper.ToJson(data);

                        return(Json(new OperationResult(OperationResultType.Success, JsonHelper.ToJson(data), result.Data)));
                    }
                    else
                    {
                        return(Json(new OperationResult(OperationResultType.Error, "创建Client Secret失败!")));
                    }
                }
                else
                {
                    return(Json(new OperationResult(OperationResultType.Error, "创建Client失败!")));
                }
            }
            else
            {
                return(Json(result));
            }
        }