public object Get()
        {
            // Check if the scope of the request is for site or application
            Site   site = ApplicationHelper.ResolveSite();
            string path = ApplicationHelper.ResolvePath();

            return(AnonymousAuthenticationHelper.ToJsonModel(site, path));
        }
        public object Get(string id)
        {
            AnonAuthId authId = new AnonAuthId(id);

            Site site = authId.SiteId == null ? null : SiteHelper.GetSite(authId.SiteId.Value);

            return(AnonymousAuthenticationHelper.ToJsonModel(site, authId.Path));
        }
Exemplo n.º 3
0
        private void ConfigureAnonymousAuthentication()
        {
            var router = Environment.Host.RouteBuilder;
            var hal    = Environment.Hal;

            router.MapWebApiRoute(Defines.AnonAuthResource.Guid, $"{Defines.ANON_AUTH_PATH}/{{id?}}", new { controller = "anonauth" });

            hal.ProvideLink(Defines.AnonAuthResource.Guid, "self", anonAuth => new { href = $"/{Defines.ANON_AUTH_PATH}/{anonAuth.id}" });

            hal.ProvideLink(Defines.AuthenticationResource.Guid, Defines.AnonAuthResource.Name, auth => {
                var authId     = new AuthenticationId((string)auth.id);
                Site site      = authId.SiteId == null ? null : SiteHelper.GetSite(authId.SiteId.Value);
                var anonAuthId = new AnonAuthId(authId.SiteId, authId.Path, AnonymousAuthenticationHelper.IsSectionLocal(site, authId.Path));
                return(new { href = $"/{Defines.ANON_AUTH_PATH}/{anonAuthId.Uuid}" });
            });
        }
        public void Delete(string id)
        {
            AnonAuthId authId = new AnonAuthId(id);

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;

            Site site = (authId.SiteId != null) ? SiteHelper.GetSite(authId.SiteId.Value) : null;

            if (site == null)
            {
                return;
            }

            AnonymousAuthenticationHelper.GetSection(site, authId.Path, ManagementUnit.ResolveConfigScope()).RevertToParent();

            ManagementUnit.Current.Commit();
        }
        public object Patch(string id, [FromBody] dynamic model)
        {
            AnonAuthId authId = new AnonAuthId(id);

            Site site = authId.SiteId == null ? null : SiteHelper.GetSite(authId.SiteId.Value);

            // Targetting section for a site, but unable to find that site
            if (authId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);

            AnonymousAuthenticationHelper.UpdateSettings(model, site, authId.Path, configPath);

            ManagementUnit.Current.Commit();

            return(AnonymousAuthenticationHelper.ToJsonModel(site, authId.Path));
        }