Esempio n. 1
0
        public virtual CoreServiceResponse RegisterApplication(ProcessDescriptor descriptor)
        {
            try
            {
                Args.ThrowIfNull(descriptor?.Application?.Name, "descriptor.Application.Name");
                Args.ThrowIfNull(descriptor?.Application?.Organization?.Name, "descriptor.Application.Organization.Name");

                string organizationName = descriptor.Application.Organization.Name;
                if (CurrentUser.Equals(UserAccounts.Data.User.Anonymous))
                {
                    return(new CoreServiceResponse <ApplicationRegistrationResult> {
                        Success = false, Message = "You must be logged in to do that", Data = new ApplicationRegistrationResult {
                            Status = ApplicationRegistrationStatus.Unauthorized
                        }
                    });
                }
                User user = CoreRegistryRepository.OneUserWhere(c => c.UserName == CurrentUser.UserName);
                if (user == null)
                {
                    user = new User()
                    {
                        UserName = CurrentUser.UserName,
                        Email    = CurrentUser.Email
                    };
                    user = CoreRegistryRepository.Save(user);
                }
                OrganizationFactory orgEnforcer             = new OrganizationFactory(CoreRegistryRepository, user, organizationName);
                CoreServiceResponse <Organization> response = orgEnforcer.Execute();
                if (!response.Success)
                {
                    return(response);
                }
                Organization             org         = response.TypedData();
                ClientApplicationFactory appEnforcer = new ClientApplicationFactory(this, user, organizationName, descriptor);
                CoreServiceResponse <ApplicationRegistration.Application> appResponse = appEnforcer.Execute();
                if (appResponse.Success)
                {
                    ApplicationRegistration.Application app = appResponse.TypedData();
                    return(new CoreServiceResponse <ApplicationRegistrationResult>(
                               new ApplicationRegistrationResult
                    {
                        Status = ApplicationRegistrationStatus.Success,
                        ClientId = app.Cuid,
                        ApiKey = app.ApiKeys.First().SharedSecret
                    })
                    {
                        Success = true
                    });
                }
                return(appResponse);
            }
            catch (Exception ex)
            {
                Logger.AddEntry("Exception occurred in {0}", ex, nameof(CoreApplicationRegistrationService.RegisterApplication));
                return(new CoreServiceResponse {
                    Success = false, Message = ex.Message
                });
            }
        }
Esempio n. 2
0
        protected internal ApiKeyInfo GenerateApiKeyInfo(ApplicationRegistration.Application app)
        {
            ApiKeyInfo info = new ApiKeyInfo();

            info.ApplicationNameProvider = new StaticApplicationNameProvider(app.Name);
            info.ApplicationClientId     = app.Cuid;
            info.ApiKey = ServiceProxySystem.GenerateId();
            return(info);
        }
Esempio n. 3
0
 public virtual string GetApplicationApiKey(string applicationClientId, int index)
 {
     ApplicationRegistration.Application app = CoreRegistryRepository.OneApplicationWhere(c => c.Cuid == applicationClientId);
     if (app != null)
     {
         return(app.ApiKeys[index]?.SharedSecret);
     }
     return(string.Empty);
 }
Esempio n. 4
0
 public virtual ApiKeyInfo AddApiKey()
 {
     if (ApplicationName.Equals(ApplicationDiagnosticInfo.UnknownApplication))
     {
         throw new ApplicationNameNotSpecifiedException();
     }
     ApplicationRegistration.Application app = CompositeRepository.Query <ApplicationRegistration.Application>(a => a.Name.Equals(ApplicationName)).FirstOrDefault();
     if (app == null)
     {
         throw new InvalidOperationException("Application not registered");
     }
     AddApiKey(CoreRegistryRepository, app, out ApplicationRegistration.ApiKey key);
     return(new ApiKeyInfo {
         ApplicationClientId = key.ClientId, ApiKey = key.SharedSecret, ApplicationName = ApplicationName
     });
 }
Esempio n. 5
0
        protected internal ApplicationRegistration.Application AddApiKey(ApplicationRegistrationRepository repo, ApplicationRegistration.Application app, out ApplicationRegistration.ApiKey key)
        {
            ApiKeyInfo keyInfo = GenerateApiKeyInfo(app);

            key           = ApplicationRegistration.ApiKey.FromKeyInfo(keyInfo);
            key.Created   = DateTime.UtcNow;
            key.CreatedBy = CurrentUser.UserName;
            app.ApiKeys.Add(key);
            app = repo.Save(app);
            return(app);
        }
Esempio n. 6
0
 /// <summary>
 /// Adds an api key and saves the app to the specified repository
 /// </summary>
 /// <param name="repo"></param>
 /// <param name="app"></param>
 /// <returns></returns>
 protected internal ApplicationRegistration.Application AddApiKey(ApplicationRegistrationRepository repo, ApplicationRegistration.Application app)
 {
     ApplicationRegistration.ApiKey ignore;
     return(AddApiKey(repo, app, out ignore));
 }
Esempio n. 7
0
 public string GetApplicationClientId(IApplicationNameProvider nameProvider)
 {
     ApplicationRegistration.Application app = CoreRegistryRepository.OneApplicationWhere(c => c.Name == nameProvider.GetApplicationName());
     return(app?.Cuid);
 }