public ApplicationToken CreateNewToken(int id, int tokenId, LoggedInUserDetails user) { // Check whehter organisation is not active if (!user.Organization.IsActive) { throw new BaseException( "Your organization is inactive. Please check if your organization has approved Legal Officer. For more details contact DataLinker administrator."); } // Check whether application belongs to a user _security.CheckAccessToApplication(user, id); // Get application token var appToken = _tokens.FirstOrDefault(i => i.ID == tokenId); // Check whether app token not found if (appToken == null) { throw new BaseException("Unable to find service host."); } // Generate new token var generatedToken = TokensHelper.GenerateToken(); var result = new ApplicationToken() { ApplicationID = appToken.ApplicationID, OriginHost = appToken.OriginHost, Token = generatedToken, CreatedAt = GetDate, CreatedBy = user.ID.Value }; // Save token _tokens.Add(result); // Setup expiration details for old token appToken.ExpiredAt = GetDate; appToken.ExpiredBy = user.ID.Value; // Save changes _tokens.Update(appToken); // Return result return(result); }
public void AddHost(int id, string host, LoggedInUserDetails user) { // Check whether organisation is not active if (!user.Organization.IsActive) { throw new BaseException( "Your organization is inactive. Please check if your organization has approved Legal Officer. For more details contact DataLinker administrator."); } // Check whether host is a valid uri var isValidUrl = Uri.TryCreate(host, UriKind.Absolute, out var result); // Check whether url scheme specified var urlWithScheme = isValidUrl && (result.Scheme == Uri.UriSchemeHttp || result.Scheme == Uri.UriSchemeHttps); if (!urlWithScheme) { throw new BaseException($"Invalid host '{result}'"); } // Get application var application = _security.CheckAccessToApplication(user, id); // Setup new application token var appToken = new ApplicationToken { ApplicationID = application.ID, OriginHost = host, Token = TokensHelper.GenerateToken(), CreatedAt = GetDate, CreatedBy = user.ID.Value }; // Add new token _tokens.Add(appToken); }
public Application Create(string url, NewApplicationDetails model, LoggedInUserDetails user) { // Check whether user has access if (user.IsSysAdmin) { throw new BaseException("Admin can not create an application."); } // Check whether organisation is active if (!user.Organization.IsActive) { throw new BaseException( "Your organization is inactive. Please check if your organization has approved Legal Officer. For more details contact DataLinker administrator."); } // Check whether application name already used within the organisation if (IsApplicationExistsForThisOrganization(model.Name, string.Empty, user)) { throw new BaseException("Application name already in use."); } // Check whether hosts provided if (string.IsNullOrEmpty(model.OriginHosts)) { throw new BaseException("You should define at least one host."); } // TODO: check whether all required data provided[Failed when auth tab was now shown in create provider app] // Setup application model var application = new Application { Name = model.Name, Description = model.Description, PublicID = Guid.NewGuid(), IsProvider = model.IsProvider, IsIntroducedAsIndustryGood = model.IsIntroducedAsIndustryGood, OrganizationID = user.Organization.ID, CreatedAt = GetDate, IsActive = !model.IsIntroducedAsIndustryGood, CreatedBy = user.ID.Value }; // Add application _applications.Add(application); if (application.IsProvider) { // Setup application authentication var appAuth = new ApplicationAuthentication { ApplicationID = application.ID, WellKnownUrl = string.IsNullOrEmpty(model.WellKnownUrl) ? string.Empty : model.WellKnownUrl, Issuer = string.IsNullOrEmpty(model.Issuer) ? string.Empty : model.Issuer, JwksUri = string.IsNullOrEmpty(model.JwksUri) ? string.Empty : model.JwksUri, AuthorizationEndpoint = model.AuthorizationEndpoint, TokenEndpoint = model.TokenEndpoint, RegistrationEndpoint = model.RegistrationEndpoint, UserInfoEndpoint = string.Empty, EndSessionEndpoint = string.Empty, CheckSessionIFrame = string.Empty, RevocationEndpoint = string.Empty, CreatedAt = GetDate, CreatedBy = user.ID.Value }; // Add application authentication _authentications.Add(appAuth); } foreach (var host in model.OriginHosts.Split(',')) { var appToken = new ApplicationToken() { ApplicationID = application.ID, OriginHost = host, Token = TokensHelper.GenerateToken(), CreatedAt = GetDate, CreatedBy = user.ID.Value }; // Add token _tokens.Add(appToken); } // Send verification request to admin for industry good application if (application.IsIntroducedAsIndustryGood) { _notifications.Admin.NewIndustryGoodApplicationInBackground(url, application.OrganizationID); } return(application); }