Example #1
0
        public async Task <UserCreateClientModel> UserCreateClient(string userId, UserCreateClientBindingModel model)
        {
            var newClient = new Domain.Entity.Client
            {
                Id                   = ObjectId.GenerateNewId().ToString(),
                Active               = true,
                ApplicationType      = GetApplicationTypeEnum(model.ApplicationType),
                UserId               = userId,
                AllowedOrigin        = "*",
                RefreshTokenLifeTime = 10080
            };
            var result = new UserCreateClientModel
            {
                Id      = newClient.Id,
                Message = "client_id: " + newClient.Id
            };

            if (model.ApplicationType.ToUpper().Equals("JAVA SCRIPT"))
            {
                if (string.IsNullOrEmpty(model.AllowedOrigin) || model.AllowedOrigin.Equals("*"))
                {
                    CustomException.ThrowBadRequestException("Provide AllowedOrigin for cors support");
                }

                var secret = GenerateClientSecret();
                newClient.Secret        = GetHash(secret);
                newClient.AllowedOrigin = model.AllowedOrigin;
                result.Message         += Environment.NewLine + "client_secret: " + secret;
            }

            await Context.GetClientCollection().InsertOneAsync(newClient);

            return(result);
        }
Example #2
0
        public async Task<IHttpActionResult> UserCreateClient(UserCreateClientBindingModel model)
        {
            var userId = User.Identity.GetUserId();

            var result = await _clientService.UserCreateClient(userId, model);

            await _userManager.SendEmailAsync(userId, "New client", $"{result.Message}");

            var newClient = await _clientService.GetUserCreatedClient(result.Id);
            Uri locationHeader = new Uri(Url.Link("MyClient", new { id = result.Id }));
            return Created(locationHeader, newClient);
        }