private OpenApiDocument CreateApiDocument(HttpContext context, IAppEntity app)
        {
            var appName = app.Name;

            var scheme =
                string.Equals(context.Request.Scheme, "http", StringComparison.OrdinalIgnoreCase) ?
                OpenApiSchema.Http :
                OpenApiSchema.Https;

            var document = new OpenApiDocument
            {
                Schemes = new List <OpenApiSchema>
                {
                    scheme
                },
                Consumes = new List <string>
                {
                    "application/json"
                },
                Produces = new List <string>
                {
                    "application/json"
                },
                Info = new OpenApiInfo
                {
                    Title       = $"Squidex Content API for '{appName}' App",
                    Description =
                        Properties.Resources.OpenApiContentDescription
                        .Replace("[REDOC_LINK_NORMAL]", urlGenerator.BuildUrl($"api/content/{app.Name}/docs"))
                        .Replace("[REDOC_LINK_SIMPLE]", urlGenerator.BuildUrl($"api/content/{app.Name}/docs/flat"))
                },
                SchemaType = SchemaType.OpenApi3
            };

            if (!string.IsNullOrWhiteSpace(context.Request.Host.Value))
            {
                document.Host = context.Request.Host.Value;
            }

            return(document);
        }
        public IActionResult GetLog(string app)
        {
            var token = dataProtector.Protect(App.Id.ToString());

            var url = urlGenerator.BuildUrl($"/api/apps/log/{token}/");

            var response = new LogDownloadDto {
                DownloadUrl = url
            };

            return(Ok(response));
        }
Exemple #3
0
        public SourceDto Invoke()
        {
            if (!_mapData.HasLayer(WorkspaceId, LayerId))
            {
                throw new EntityNotFoundException();
            }
            var src = _mapData.GetLayer(WorkspaceId, LayerId).Source;

            src.Tiles = new[]
            { $"{_urlGenerator.BuildUrl(RouteNames.GetLayer, new {WorkspaceId, LayerId})}/tile" + "/{x}/{y}/{z}" };
            return(src);
        }
        private static OpenApiSecurityScheme CreateOAuthSchema(IUrlGenerator urlGenerator)
        {
            var security = new OpenApiSecurityScheme
            {
                Type = OpenApiSecuritySchemeType.OAuth2
            };

            var tokenUrl = urlGenerator.BuildUrl($"{Constants.IdentityServerPrefix}/connect/token", false);

            security.TokenUrl = tokenUrl;

            SetupDescription(security, tokenUrl);
            SetupFlow(security);
            SetupScopes(security);

            return(security);
        }
        public IList <LinkDto> GenerateResourceLinks(string workspaceId, string layerId)
        {
            var links = new List <LinkDto>();

            var baseUrl = _urlGenerator.BuildUrl(RouteNames.GetLayer, new { workspaceId, layerId });

            links.Add(new LinkDto(LinkRelations.Self, baseUrl));
            links.Add(new LinkDto(LinkRelations.Source, _urlGenerator.BuildUrl(RouteNames.GetLayerSource, new { workspaceId, layerId })));
            links.Add(new LinkDto(LinkRelations.Style, _urlGenerator.BuildUrl(RouteNames.GetLayerStyle, new { workspaceId, layerId })));
            links.Add(new LinkDto(LinkRelations.Status, _urlGenerator.BuildUrl(RouteNames.GetLayerStatus, new { workspaceId, layerId })));
            links.Add(new LinkDto(LinkRelations.Maptiles, _urlGenerator.BuildUrl(RouteNames.GetLayerMbtiles, new { workspaceId, layerId })));
            links.Add(new LinkDto(LinkRelations.MaptilesHash, _urlGenerator.BuildUrl(RouteNames.GetLayerMbtilesHash, new { workspaceId, layerId })));
            links.Add(new LinkDto(LinkRelations.Metadata, _urlGenerator.BuildUrl(RouteNames.GetLayerMetaData, new { workspaceId, layerId })));
            links.Add(new LinkDto(LinkRelations.Geojson, _urlGenerator.BuildUrl(RouteNames.GetLayerGeoJson, new { workspaceId, layerId })));
            links.Add(new LinkDto(LinkRelations.Tile, $"{baseUrl}/{DataContracts.V2.Resources.TileSubResource}/" + "{x}/{y}/{z}"));
            links.Add(new LinkDto(LinkRelations.Grid, $"{baseUrl}/{DataContracts.V2.Resources.GridSubResource}/" + "{x}/{y}/{z}"));

            return(links);
        }
Exemple #6
0
        private async Task <SetupVM> GetVM <TModel>(TModel?model = null, string?errorMessage = null) where TModel : class
        {
            var externalProviders = await SignInManager.GetExternalProvidersAsync();

            var result = new SetupVM
            {
                BaseUrlConfigured      = urlGenerator.BuildUrl(string.Empty, false),
                BaseUrlCurrent         = GetCurrentUrl(),
                ErrorMessage           = errorMessage,
                EverybodyCanCreateApps = !uiOptions.OnlyAdminsCanCreateApps,
                IsValidHttps           = HttpContext.Request.IsHttps,
                IsAssetStoreFile       = assetStore is FolderAssetStore,
                IsAssetStoreFtp        = assetStore is FTPAssetStore,
                HasExternalLogin       = externalProviders.Any(),
                HasPasswordAuth        = identityOptions.AllowPasswordAuth
            };

            if (model != null)
            {
                SimpleMapper.Map(model, result);
            }

            return(result);
        }
Exemple #7
0
 public string EmailPreferences(string apiKey, string language)
 {
     return(urlGenerator.BuildUrl($"api/email-preferences?access_token={apiKey}&amp;culture={language}"));
 }
Exemple #8
0
 public ImageFormatter(IUrlGenerator urlGenerator)
 {
     Uri.TryCreate(urlGenerator.BuildUrl(), UriKind.Absolute, out baseUrl);
 }
Exemple #9
0
 public string TrackConfirmed(Guid notificationId, string language)
 {
     return(urlGenerator.BuildUrl($"api/tracking/notifications/{notificationId}/confirm?culture={language}"));
 }
Exemple #10
0
        private static IEnumerable <Client> CreateStaticClients(IUrlGenerator urlGenerator, MyIdentityOptions identityOptions)
        {
            var frontendId = Constants.FrontendClient;

            yield return(new Client
            {
                ClientId = frontendId,
                ClientName = frontendId,
                RedirectUris = new List <string>
                {
                    urlGenerator.BuildUrl("login;"),
                    urlGenerator.BuildUrl("client-callback-silent", false),
                    urlGenerator.BuildUrl("client-callback-popup", false)
                },
                PostLogoutRedirectUris = new List <string>
                {
                    urlGenerator.BuildUrl("logout", false)
                },
                AllowAccessTokensViaBrowser = true,
                AllowedGrantTypes = GrantTypes.Implicit,
                AllowedScopes = new List <string>
                {
                    IdentityServerConstants.StandardScopes.OpenId,
                    IdentityServerConstants.StandardScopes.Profile,
                    IdentityServerConstants.StandardScopes.Email,
                    Constants.ApiScope,
                    Constants.PermissionsScope,
                    Constants.ProfileScope,
                    Constants.RoleScope
                },
                RequireConsent = false
            });

            var internalClient = Constants.InternalClientId;

            yield return(new Client
            {
                ClientId = internalClient,
                ClientName = internalClient,
                ClientSecrets = new List <Secret>
                {
                    new Secret(Constants.InternalClientSecret)
                },
                RedirectUris = new List <string>
                {
                    urlGenerator.BuildUrl($"{Constants.PortalPrefix}/signin-internal", false),
                    urlGenerator.BuildUrl($"{Constants.OrleansPrefix}/signin-internal", false)
                },
                AccessTokenLifetime = (int)TimeSpan.FromDays(30).TotalSeconds,
                AllowedGrantTypes = GrantTypes.ImplicitAndClientCredentials,
                AllowedScopes = new List <string>
                {
                    IdentityServerConstants.StandardScopes.OpenId,
                    IdentityServerConstants.StandardScopes.Profile,
                    IdentityServerConstants.StandardScopes.Email,
                    Constants.ApiScope,
                    Constants.PermissionsScope,
                    Constants.ProfileScope,
                    Constants.RoleScope
                },
                RequireConsent = false
            });

            if (identityOptions.IsAdminClientConfigured())
            {
                var id = identityOptions.AdminClientId;

                yield return(new Client
                {
                    ClientId = id,
                    ClientName = id,
                    ClientSecrets = new List <Secret>
                    {
                        new Secret(identityOptions.AdminClientSecret.Sha256())
                    },
                    AccessTokenLifetime = (int)TimeSpan.FromDays(30).TotalSeconds,
                    AllowedGrantTypes = GrantTypes.ClientCredentials,
                    AllowedScopes = new List <string>
                    {
                        Constants.ApiScope,
                        Constants.RoleScope,
                        Constants.PermissionsScope
                    },
                    Claims = new List <ClientClaim>
                    {
                        new ClientClaim(SquidexClaimTypes.Permissions, Permissions.All)
                    }
                });
            }
        }