public bool HostDomainIsAuthorized() { IRequest request = HttpContext?.Request; string host = request.Url?.Host; int port = (request?.Url?.Port).Value; Bam.Net.CoreServices.ApplicationRegistration.Data.Application app = GetServerApplicationOrDie(); if (app.HostDomains.Count > 0) { HostDomain hd = app.HostDomains.Where(h => h.DomainName.Equals(host) && h.Port.Equals(port)).FirstOrDefault(); return(hd == null ? false : hd.Authorized); } else { HostDomain hd = new HostDomain { Authorized = true, DomainName = host, DefaultApplicationName = app.Name, Port = port }; app.HostDomains.Add(hd); Task.Run(() => ApplicationRegistrationRepository.Save(app)); return(true); } }
public CoreServiceResponse AddProvider(string providerName, string clientId, string clientSecret) { try { ApplicationRegistration.Data.Application app = GetServerApplicationOrDie(); OAuthSettingsData data = new OAuthSettingsData() { ApplicationName = app.Name, ApplicationIdentifier = app.Cuid, ProviderName = providerName, ClientId = clientId, ClientSecret = clientSecret }; OAuthClientSettings settings = OAuthSettingsRepository.Save(data).CopyAs <OAuthClientSettings>(); return(new CoreServiceResponse { Success = true, Data = settings }); } catch (Exception ex) { return(new CoreServiceResponse { Success = false, Message = ex.Message }); } }
public CoreServiceResponse RemoveProvider(string providerName) { try { ApplicationRegistration.Data.Application app = GetServerApplicationOrDie(); OAuthSettingsData data = OAuthSettingsRepository.OneOAuthSettingsDataWhere(c => c.ApplicationIdentifier == app.Cuid && c.ApplicationName == app.Name && c.ProviderName == providerName); if (data != null) { bool success = OAuthSettingsRepository.Delete(data); if (!success) { throw OAuthSettingsRepository.LastException; } return(new CoreServiceResponse { Success = OAuthSettingsRepository.Delete(data) }); } throw new InvalidOperationException($"OAuthSettings not found: AppId={app.Cuid}, AppName={app.Name}, Provider={providerName}"); } catch (Exception ex) { return(new CoreServiceResponse { Success = false, Message = ex.Message }); } }
protected internal Bam.Net.CoreServices.ApplicationRegistration.Data.Application GetServerApplicationOrDie() { Bam.Net.CoreServices.ApplicationRegistration.Data.Application app = ApplicationRegistrationRepository.GetOneApplicationWhere(c => c.Name == ServerApplicationName); if (app.Equals(ApplicationRegistration.Data.Application.Unknown)) { throw new InvalidOperationException("Application is Uknown"); } return(app); }
public CoreServiceResponse GetClientSettings() { try { ApplicationRegistration.Data.Application app = ApplicationRegistrationRepository.GetOneApplicationWhere(c => c.Name == base.ApplicationName); return(new CoreServiceResponse ( OAuthSettingsRepository .OAuthSettingsDatasWhere(c => c.ApplicationIdentifier == app.Cuid && c.ApplicationName == app.Name) .Select(sd => OAuthSettings.FromData(sd)) .Select(os => os.CopyAs <OAuthClientSettings>()) .ToArray() )); } catch (Exception ex) { return(new CoreServiceResponse { Success = false, Message = ex.Message }); } }