Skip to content

Implements preview tokens #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Users referenced in this file will automatically be requested as reviewers for PRs that modify the given paths.

# See https://help.github.com/articles/about-code-owners/

# Default owners for everything in this repo
* @hennys @shahramshahram @johanpetersson @jbearfoot @pergunsarfs @tidyui

- @episerver/cms-delivery
39 changes: 20 additions & 19 deletions samples/music-festival-vue-decoupled/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,41 @@ Content is fetched from Optimizely using the Content Delivery API: https://world
## Prerequisites

This project uses:
* Node.js 18+
* .NET SDK 6+
* SQL Server 2016 Express LocalDB ([download here](https://www.microsoft.com/en-us/sql-server/sql-server-downloads))

- Node.js 18+
- .NET SDK 9+
- SQL Server 2016 Express LocalDB ([download here](https://www.microsoft.com/en-us/sql-server/sql-server-downloads))

## Setup and Run

1. Run `setup.cmd`. You can re-run `setup.cmd` at any time to reset the backend with a fresh database.
2. Open terminal for `./backend` and run `dotnet run`.
* Navigate to http://localhost:8081/.
* Create an admin user. If the UI is not displayed automatically, navigate to http://localhost:8081/util/register.
* Now you can access http://localhost:8081/episerver/cms.
- Navigate to http://localhost:8081/.
- Create an admin user. If the UI is not displayed automatically, navigate to http://localhost:8081/util/register.
- Now you can access http://localhost:8081/episerver/cms.
3. Since we reference two NPM modules locally, we need to install them first (this is not needed if you install the modules from npmjs.com).
* Open terminal for `../../src/@episerver/content-definitions` and run `npm install` (only needed first run).
* Open terminal for `../../src/@episerver/content-delivery` and run `npm install` (only needed first run).
- Open terminal for `../../src/@episerver/content-definitions` and run `npm install` (only needed first run).
- Open terminal for `../../src/@episerver/content-delivery` and run `npm install` (only needed first run).
4. Open terminal for `./frontend` and run `npm install` (only needed first run).
* Run `npm run serve`.
* Navigate to http://localhost:8080/.
- Run `npm run serve`.
- Navigate to http://localhost:8080/.

## Notable files

### Vuex store modules

* [epiContext.js](frontend/src/store/modules/epiContext.js): makes `inEditMode` and `isEditable` flags available to the OPE helpers.
* [epiDataModel.js](frontend/src/store/modules/epiDataModel.js): the module that stores and updates the model object to be displayed on every component.
- [epiContext.js](frontend/src/store/modules/epiContext.js): makes `inEditMode` and `isEditable` flags available to the OPE helpers.
- [epiDataModel.js](frontend/src/store/modules/epiDataModel.js): the module that stores and updates the model object to be displayed on every component.

### On-Page Editing helpers

* [epiBootstrap.js](frontend/src/epiBootstrap.js): registers the `contentSaved` and `epiReady` message handlers that updates the vuex store.
* [epiEdit.js](frontend/src/directives/epiEdit.js): a directive that can be added on components to make them optionally editable (e.g. `<span v-epi-edit="Name">`), through `isEditable` and `epiDisableEditing`.
* [EpiProperty.vue](frontend/src/components/EpiProperty.vue): a component that renders a button to edit a property (e.g. `<epi-property property-name="Name">`).
- [epiBootstrap.js](frontend/src/epiBootstrap.js): registers the `contentSaved` and `epiReady` message handlers that updates the vuex store.
- [epiEdit.js](frontend/src/directives/epiEdit.js): a directive that can be added on components to make them optionally editable (e.g. `<span v-epi-edit="Name">`), through `isEditable` and `epiDisableEditing`.
- [EpiProperty.vue](frontend/src/components/EpiProperty.vue): a component that renders a button to edit a property (e.g. `<epi-property property-name="Name">`).

### Routing helpers

* [EpiPageComponentSelector.vue](frontend/src/components/EpiPageComponentSelector.vue): loads the Vue page component and owns its model.
* [EpiBlockComponentSelector.vue](frontend/src/components/EpiBlockComponentSelector.vue): loads the Vue block component.
* [EpiLink.vue](frontend/src/components/EpiLink.vue): regular links when in OPE and Vue router links otherwise.
* [EpiViewModeLink.vue](frontend/src/components/EpiViewModeLink.vue): disables links completely when in OPE.
- [EpiPageComponentSelector.vue](frontend/src/components/EpiPageComponentSelector.vue): loads the Vue page component and owns its model.
- [EpiBlockComponentSelector.vue](frontend/src/components/EpiBlockComponentSelector.vue): loads the Vue block component.
- [EpiLink.vue](frontend/src/components/EpiLink.vue): regular links when in OPE and Vue router links otherwise.
- [EpiViewModeLink.vue](frontend/src/components/EpiViewModeLink.vue): disables links completely when in OPE.
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>MusicFestival.Backend</RootNamespace>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EPiServer.CMS" Version="12.23.0" />
<PackageReference Include="EPiServer.ContentDefinitionsApi" Version="3.9.0" />
<PackageReference Include="EPiServer.ContentDeliveryApi.Cms" Version="3.9.0" />
<PackageReference Include="EPiServer.OpenIDConnect" Version="3.9.0" />
<PackageReference Include="EPiServer.OpenIDConnect.UI" Version="3.9.0" />
<PackageReference Include="EPiServer.CMS" Version="12.32.5" />
<PackageReference Include="EPiServer.ContentDeliveryApi.Cms" Version="3.12.2" />
</ItemGroup>

</Project>
40 changes: 4 additions & 36 deletions samples/music-festival-vue-decoupled/backend/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
using EPiServer.Cms.UI.AspNetIdentity;
using EPiServer.ContentApi.Cms;
using EPiServer.ContentApi.Core.DependencyInjection;
using EPiServer.ContentDefinitionsApi;
using EPiServer.Core;
using EPiServer.OpenIDConnect;
using EPiServer.Security;
using EPiServer.ServiceLocation;
using EPiServer.Web;
using EPiServer.Web.Routing;
Expand Down Expand Up @@ -41,39 +40,9 @@ public void ConfigureServices(IServiceCollection services)
.Add("narrow", "Narrow", "u-md-size1of3", string.Empty, "epi-icon__layout--one-third");
});

services.AddOpenIDConnect<ApplicationUser>(
useDevelopmentCertificate: true,
signingCertificate: null,
encryptionCertificate: null,
createSchema: true,
options =>
{
options.RequireHttps = !_webHostingEnvironment.IsDevelopment();

options.Applications.Add(new OpenIDConnectApplication
{
ClientId = "frontend",
Scopes = { "openid", "offline_access", "profile", "email", "roles", ContentDeliveryApiOptionsDefaults.Scope },
PostLogoutRedirectUris = { _frontendUri },
RedirectUris =
{
new Uri(_frontendUri, "/login-callback"),
new Uri(_frontendUri, "/login-renewal"),
},
});

options.Applications.Add(new OpenIDConnectApplication
{
ClientId = "cli",
ClientSecret = "cli",
Scopes = { ContentDefinitionsApiOptionsDefaults.Scope },
});
});

services.AddOpenIDConnectUI();
services.Configure<UIOptions>(options => options.UsePreviewTokens = true);

services.AddContentDefinitionsApi(OpenIDConnectOptionsDefaults.AuthenticationScheme);
services.AddContentDeliveryApi(OpenIDConnectOptionsDefaults.AuthenticationScheme);
services.AddContentDeliveryApi(PreviewTokenOptions.SchemeName);
services.ConfigureForContentDeliveryClient();

services.AddHostedService<ProvisionDatabase>();
Expand All @@ -90,9 +59,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseRouting();

app.UseCors(b => b
.WithOrigins(new[] { "http://localhost:8080" })
.WithOrigins(["http://localhost:8080"])
.WithExposedContentDeliveryApiHeaders()
.WithExposedContentDefinitionApiHeaders()
.WithHeaders("Authorization")
.AllowAnyMethod()
.AllowCredentials());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"MusicFestival.Backend": {
"commandName": "Project",
"dotnetRunMessages": "true",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:8081",
"launchUrl": "episerver/cms",
Expand All @@ -11,4 +11,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
VUE_APP_CONTENT_DELIVERY_API=http://localhost:8081
VUE_APP_LOGIN_AUTHORITY=http://localhost:8081
VUE_APP_LOGIN_CLIENT_ID=frontend
VUE_APP_CONTENT_DELIVERY_API=http://localhost:8081
4 changes: 1 addition & 3 deletions samples/music-festival-vue-decoupled/frontend/.env.test
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
VUE_APP_CONTENT_DELIVERY_API=http://localhost:8081
VUE_APP_LOGIN_AUTHORITY=http://localhost:8081
VUE_APP_LOGIN_CLIENT_ID=frontend
VUE_APP_CONTENT_DELIVERY_API=http://localhost:8081
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.Build.NoTargets/3.0.4">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
<EnableNETAnalyzers>false</EnableNETAnalyzers>
Expand Down
Loading