Closed zoinkydoink closed 4 years ago
Hi there! You can initialize the api module with:
options.UseApi(o => o.AllowAnonymousAccess = true);
Best regards
As for authentication, the endpoints use the standard AuthorizationManager
of ASP.NET
which checks for Policies
. These policies are made up of one or sever claims and are defined here in the WebApi
module:
By default Piranha is configured with cookie based authentication using ASP.NET Identity
, which means you need to login and get a cookie from the server to be authenticated. However in a purely headless scenario this is most likely not the preferred authentication model, so I'd suggest looking into the different methods Identity
supports. In the end, Piranha will only look at the current user and its claims.
https://localhost:44305/api/page/getbyslug?slug=home
gets me null (200 code) even though that is the slug of he page
The correct syntax for calling that endpoint would be
https://localhost:44305/api/page/home
Above worked, one more questions, after finally seeing the results I see there is a lot of bits and pieces that make up a page. Is there a .ToHtml property or similiar anywhere in returned result (which hopefully will include urls of images if any) so that I can just get the source of the content instead of all the blocks and their html individually.
Since Piranha is a headless/decoupled CMS the core framework has no idea how the data should be rendered, as an example a ColumnBlock
would almost always need some kind of grid system to be rendered correctly. You could implement such an API yourself for your specific application.
Best regards
- Added the package
Piranha.WebApi
- added
options.UseApi();
- I created a page called
home
with the same slug- Using PostMan REST Client, accessing
https://localhost:44305/api/page/GetBySlug?slug=home
(might be issue here)- Getting 401 error
Unauthorized
- I tried sending Basic Authentication with it using
admin/pass
, still same issueI have the /manager accessible by
admin/password
so I assume that is what is needed to be sent, the default identity isIdentitySqlLiteDb
if it matters.I looked at the code for the .WebApi package and it seems to fail at the following.
[HttpGet] [Route("{slug}")] public async Task<IActionResult> GetBySlug(string slug) { if (!Module.AllowAnonymousAccess) { if (!(await _auth.AuthorizeAsync(User, Permissions.Pages)).Succeeded) { return Unauthorized(); } } return Json(await _api.Pages.GetBySlugAsync<PageBase>(slug)); }
How do I configure this specific module so that
Anonymous
access is allowed and not even ask/require credentials?I am simply trying to have a cms where I can enter content through /manager and then be able to access all created pages using the api (hopefully) without even any type of authentication.
I understand I can role my own API and remove the checks where it asks for creds but I would like to understand the process better and even prefer to use the built in provided by you guys.
See this to: https://gist.github.com/biapar/e48bb57e86759c9ffb14fdabbf804369
Piranha.WebApi
options.UseApi();
home
with the same slughttps://localhost:44305/api/page/GetBySlug?slug=home
(might be issue here)Unauthorized
admin/pass
, still same issueI have the /manager accessible by
admin/password
so I assume that is what is needed to be sent, the default identity isIdentitySqlLiteDb
if it matters.I looked at the code for the .WebApi package and it seems to fail at the following.
How do I configure this specific module so that
Anonymous
access is allowed and not even ask/require credentials?I am simply trying to have a cms where I can enter content through /manager and then be able to access all created pages using the api (hopefully) without even any type of authentication.
I understand I can role my own API and remove the checks where it asks for creds but I would like to understand the process better and even prefer to use the built in provided by you guys.