Ejemplo n.º 1
0
        public static SwaggerSecurityScheme CreateOAuthSchema(MyUrlsOptions urlOptions)
        {
            var tokenUrl = urlOptions.BuildUrl($"{Constants.IdentityServerPrefix}/connect/token");

            var securityDocs = LoadDocs("security");
            var securityText = securityDocs.Replace("<TOKEN_URL>", tokenUrl);

            var result =
                new SwaggerSecurityScheme
            {
                TokenUrl = tokenUrl,
                Type     = SwaggerSecuritySchemeType.OAuth2,
                Flow     = SwaggerOAuth2Flow.Application,
                Scopes   = new Dictionary <string, string>
                {
                    { Constants.ApiScope, "Read and write access to the API" },
                    { SquidexRoles.AppOwner, "App contributor with Owner permission." },
                    { SquidexRoles.AppEditor, "Client (writer) or App contributor with Editor permission." },
                    { SquidexRoles.AppReader, "Client (readonly) or App contributor with Editor permission." },
                    { SquidexRoles.AppDeveloper, "App contributor with Developer permission." }
                },
                Description = securityText
            };

            return(result);
        }
Ejemplo n.º 2
0
        public static SwaggerSecurityScheme CreateOAuthSchema(MyUrlsOptions urlOptions)
        {
            var tokenUrl = urlOptions.BuildUrl($"{Constants.IdentityPrefix}/connect/token");

            var securityDocs        = LoadDocs("security");
            var securityDescription = securityDocs.Replace("<TOKEN_URL>", tokenUrl);

            var result =
                new SwaggerSecurityScheme
            {
                TokenUrl = tokenUrl,
                Type     = SwaggerSecuritySchemeType.OAuth2,
                Flow     = SwaggerOAuth2Flow.Application,
                Scopes   = new Dictionary <string, string>
                {
                    { Constants.ApiScope, "Read and write access to the API" },
                    { SquidexRoles.AppOwner, "You get this scope / role when you are owner of the app you are accessing." },
                    { SquidexRoles.AppEditor, "You get this scope / role when you are owner of the app you are accessing or when the subject is a client." },
                    { SquidexRoles.AppDeveloper, "You get this scope / role when you are owner of the app you are accessing." }
                },
                Description = securityDescription
            };

            return(result);
        }
 private void GenerateRequestInfo()
 {
     document.Info = new SwaggerInfo
     {
         ExtensionData = new Dictionary <string, object>
         {
             ["x-logo"] = new { url = urlOptions.BuildUrl("images/logo-white.png", false), backgroundColor = "#3f83df" }
         },
         Title = $"Suidex API for {app.Name} App"
     };
 }
Ejemplo n.º 4
0
        public IActionResult GetLog(string app)
        {
            var token = dataProtector.Protect(App.Id.ToString());

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

            var response = new LogDownloadDto {
                DownloadUrl = url
            };

            return(Ok(response));
        }
Ejemplo n.º 5
0
        private static IEnumerable <Client> CreateStaticClients(MyUrlsOptions urlsOptions)
        {
            var frontendId = Constants.FrontendClient;

            yield return(new Client
            {
                ClientId = frontendId,
                ClientName = frontendId,
                RedirectUris = new List <string>
                {
                    urlsOptions.BuildUrl("login;"),
                    urlsOptions.BuildUrl("client-callback-silent", false),
                    urlsOptions.BuildUrl("client-callback-popup", false)
                },
                PostLogoutRedirectUris = new List <string>
                {
                    urlsOptions.BuildUrl("logout", false)
                },
                AllowAccessTokensViaBrowser = true,
                AllowedGrantTypes = GrantTypes.Implicit,
                AllowedScopes = new List <string>
                {
                    IdentityServerConstants.StandardScopes.OpenId,
                    IdentityServerConstants.StandardScopes.Profile,
                    IdentityServerConstants.StandardScopes.Email,
                    Constants.ApiScope,
                    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>
                {
                    urlsOptions.BuildUrl($"{Constants.PortalPrefix}/signin-oidc", false),
                    urlsOptions.BuildUrl($"{Constants.OrleansPrefix}/signin-oidc", 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.ProfileScope,
                    Constants.RoleScope
                },
                RequireConsent = false
            });
        }
Ejemplo n.º 6
0
        private static SwaggerSettings ConfigurePaths(this SwaggerSettings settings, MyUrlsOptions urlOptions)
        {
            settings.SwaggerRoute = $"{Constants.ApiPrefix}/swagger/v1/swagger.json";

            settings.PostProcess = document =>
            {
                document.BasePath           = Constants.ApiPrefix;
                document.Info.ExtensionData = new Dictionary <string, object>
                {
                    ["x-logo"] = new { url = urlOptions.BuildUrl("images/logo-white.png", false), backgroundColor = "#3f83df" }
                };
            };

            settings.MiddlewareBasePath = Constants.ApiPrefix;

            return(settings);
        }
Ejemplo n.º 7
0
        public static SwaggerDocument CreateApiDocument(HttpContext context, MyUrlsOptions urlOptions, string appName)
        {
            var scheme =
                string.Equals(context.Request.Scheme, "http", StringComparison.OrdinalIgnoreCase) ?
                SwaggerSchema.Http :
                SwaggerSchema.Https;

            var document = new SwaggerDocument
            {
                Tags    = new List <SwaggerTag>(),
                Schemes = new List <SwaggerSchema>
                {
                    scheme
                },
                Consumes = new List <string>
                {
                    "application/json"
                },
                Produces = new List <string>
                {
                    "application/json"
                },
                Info = new SwaggerInfo
                {
                    ExtensionData = new Dictionary <string, object>
                    {
                        ["x-logo"] = new { url = urlOptions.BuildUrl("images/logo-white.png", false), backgroundColor = "#3f83df" }
                    },
                    Title = $"Squidex API for {appName} App", Version = "1.0"
                },
                BasePath = "/api"
            };

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

            document.SecurityDefinitions.Add(Constants.SecurityDefinition, CreateOAuthSchema(urlOptions));

            return(document);
        }
Ejemplo n.º 8
0
        public static SwaggerSecurityScheme CreateOAuthSchema(MyUrlsOptions urlOptions)
        {
            var tokenUrl = urlOptions.BuildUrl($"{Constants.IdentityServerPrefix}/connect/token", false);

            var securityDocs = LoadDocs("security");
            var securityText = securityDocs.Replace("<TOKEN_URL>", tokenUrl);

            var result =
                new SwaggerSecurityScheme
            {
                TokenUrl = tokenUrl,
                Type     = SwaggerSecuritySchemeType.OAuth2,
                Flow     = SwaggerOAuth2Flow.Application,
                Scopes   = new Dictionary <string, string>
                {
                    { Constants.ApiScope, "Read and write access to the API" }
                },
                Description = securityText
            };

            return(result);
        }
Ejemplo n.º 9
0
        private static SwaggerSecurityScheme CreateOAuthSchema(MyUrlsOptions urlOptions)
        {
            var securityScheme = new SwaggerSecurityScheme();

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

            securityScheme.TokenUrl = tokenUrl;

            var securityDocs = NSwagHelper.LoadDocs("security");
            var securityText = securityDocs.Replace("<TOKEN_URL>", tokenUrl);

            securityScheme.Description = securityText;

            securityScheme.Type = SwaggerSecuritySchemeType.OAuth2;
            securityScheme.Flow = SwaggerOAuth2Flow.Application;

            securityScheme.Scopes = new Dictionary <string, string>
            {
                [Constants.ApiScope] = "Read and write access to the API"
            };

            return(securityScheme);
        }