Skip to content

Commit 6df2927

Browse files
committed
WIP
1 parent bbc715d commit 6df2927

File tree

8 files changed

+39
-85
lines changed

8 files changed

+39
-85
lines changed

samples/musicfestival-backend-dotnet/MusicFestival.Backend.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="EPiServer.CMS" Version="12.20.0" />
12-
<PackageReference Include="EPiServer.ContentDefinitionsApi" Version="3.8.0" />
13-
<PackageReference Include="EPiServer.ContentDeliveryApi.Cms" Version="3.8.0" />
14-
<PackageReference Include="EPiServer.ContentManagementApi" Version="3.8.0" />
11+
<PackageReference Include="EPiServer.CMS" Version="12.22.4" />
12+
<PackageReference Include="EPiServer.ContentDefinitionsApi" Version="3.9.0" />
13+
<PackageReference Include="EPiServer.ContentDeliveryApi.Cms" Version="3.9.0" />
14+
<PackageReference Include="EPiServer.ContentManagementApi" Version="3.9.0" />
1515
<PackageReference Include="EPiServer.OpenIDConnect" Version="3.8.0" />
1616
<PackageReference Include="EPiServer.OpenIDConnect.UI" Version="3.8.0" />
17-
<PackageReference Include="Optimizely.ContentGraph.Cms" Version="3.0.0" />
17+
<PackageReference Include="Optimizely.ContentGraph.Cms" Version="3.4.0-pre-69547" />
1818
</ItemGroup>
1919
</Project>

samples/musicfestival-backend-dotnet/Startup.cs

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -62,64 +62,13 @@ public void ConfigureServices(IServiceCollection services)
6262
.Add("narrow", "Narrow", "u-md-size1of3", string.Empty, "epi-icon__layout--one-third");
6363
});
6464

65-
// services.AddOpenIddict();
66-
67-
Console.WriteLine("Adding OpenID Connect");
68-
services.AddOpenIDConnect<ApplicationUser>(
69-
useDevelopmentCertificate: true,
70-
signingCertificate: null,
71-
encryptionCertificate: null,
72-
createSchema: true,
73-
options =>
74-
{
75-
var baseUri = new Uri(_frontendUri);
76-
options.RequireHttps = !_webHostingEnvironment.IsDevelopment();
77-
options.DisableTokenPruning = true;
78-
options.DisableSlidingRefreshTokenExpiration = true;
79-
80-
options.Applications.Add(new OpenIDConnectApplication
81-
{
82-
ClientId = "frontend",
83-
Scopes = { "openid", "offline_access", "profile", "email", "roles", ContentDeliveryApiOptionsDefaults.Scope },
84-
PostLogoutRedirectUris = { baseUri },
85-
RedirectUris =
86-
{
87-
new Uri(baseUri, "/"),
88-
new Uri(baseUri, "/login-callback"),
89-
new Uri(baseUri, "/login-renewal"),
90-
},
91-
});
92-
93-
options.Applications.Add(new OpenIDConnectApplication
94-
{
95-
ClientId = "cli",
96-
ClientSecret = "cli",
97-
Scopes = { ContentDefinitionsApiOptionsDefaults.Scope },
98-
});
99-
});
100-
101-
services.AddOpenIDConnectUI();
102-
103-
// No encrypt the token so it's easier to debug, not recommend for production.
104-
services.AddOpenIddict()
105-
.AddServer(options => options.DisableAccessTokenEncryption());
106-
107-
services.AddContentDefinitionsApi(OpenIDConnectOptionsDefaults.AuthenticationScheme);
108-
109-
services.AddContentDeliveryApi(OpenIDConnectOptionsDefaults.AuthenticationScheme);
110-
111-
services.AddContentManagementApi(OpenIDConnectOptionsDefaults.AuthenticationScheme, options =>
65+
services.AddContentDefinitionsApi();
66+
services.AddContentDeliveryApi();
67+
services.AddContentManagementApi(options =>
11268
{
11369
options.DisableScopeValidation = false;
11470
options.RequiredRole = "WebAdmins";
11571
});
116-
// services.AddContentManagementApi(string.Empty);
117-
118-
services.AddOpenIddict()
119-
.AddServer(options =>
120-
{
121-
options.DisableAccessTokenEncryption();
122-
});
12372

12473
services.ConfigureForContentDeliveryClient();
12574

@@ -133,7 +82,10 @@ public void ConfigureServices(IServiceCollection services)
13382
o.IncludeNumericContentIdentifier = true;
13483
});
13584

136-
services.AddContentGraph(_configuration, OpenIDConnectOptionsDefaults.AuthenticationScheme);
85+
services.AddContentGraph(options =>
86+
{
87+
options.EnablePreviewTokens = true;
88+
});
13789
services.AddHostedService<ProvisionDatabase>();
13890
}
13991

samples/musicfestival-frontend-react/src/App.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { BlockPage } from './pages/BlockPage';
1616

1717
let previousSavedMessage: any = null;
1818
const singleKeyUrl = process.env.REACT_APP_CONTENT_GRAPH_GATEWAY_URL as string
19-
const hmacKeyUrl = process.env.REACT_APP_CG_PROXY_URL as string
19+
const hmacKeyUrl = process.env.REACT_APP_CG_CONTENT_URL as string
2020

2121
const App = () => {
2222
const queryClient = useQueryClient();
@@ -36,21 +36,19 @@ const App = () => {
3636
}
3737
});
3838

39-
authService.getAccessToken().then((_token) => {
40-
_token && setToken(_token)
41-
modeEdit && !_token && !data && authService.login()
42-
})
39+
const urlParams = new URLSearchParams(window.location.search);
40+
const previewToken = urlParams.get('preview_token') ?? "";
4341

44-
variables = generateGQLQueryVars(token, window.location.pathname)
42+
variables = generateGQLQueryVars(previewToken, window.location.pathname)
4543
if (modeEdit) {
46-
if (token) {
47-
headers = { 'Authorization': 'Bearer ' + token };
44+
if (previewToken) {
45+
headers = { 'Authorization': 'Bearer ' + previewToken };
4846
}
4947
url = hmacKeyUrl
5048
subcribeContentSavedEvent((message: any) => mutate(message))
5149
}
5250

53-
const { data: queryData } = useStartQuery({ endpoint: url, fetchParams: { headers: headers } }, variables, { staleTime: 2000, enabled: !modeEdit || !!token });
51+
const { data: queryData } = useStartQuery({ endpoint: url, fetchParams: { headers: headers } }, variables, { staleTime: 2000, enabled: !modeEdit || !!previewToken });
5452
data = queryData
5553

5654
if (!data) {

samples/musicfestival-frontend-react/src/components/SearchButton.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ function SearchButton({filterValue}: any): JSX.Element {
1818
const [orderBy] = useState("ASC")
1919

2020
let modeEdit = isEditOrPreviewMode()
21-
let variables = generateGQLSearchQueryVars(token, window.location.pathname, searchValue as string | null, orderBy, ranking);
21+
const urlParams = new URLSearchParams(window.location.search);
22+
const previewToken = urlParams.get('preview_token') ?? "";
23+
24+
let variables = generateGQLSearchQueryVars(previewToken, window.location.pathname, searchValue as string | null, orderBy, ranking);
2225
const autocompleteData = useArtistAutocompleteQuery({endpoint: singleKeyUrl}, variables, {
2326
staleTime: 2000,
24-
enabled: !modeEdit || !!token
27+
enabled: !modeEdit || !!previewToken
2528
}).data;
2629

2730
const onSearch = (event: any) => {

samples/musicfestival-frontend-react/src/helpers/queryCacheHelper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ContentSavedMessage } from "../models/ContentSavedMessage";
44
import { extractParams, isEditOrPreviewMode } from "./urlHelper";
55

66
const generateGQLQueryVars = (token: string, pathname: string): any => {
7-
const { relativePath, locales, language, contentId, workId } = extractParams(pathname)
7+
const { relativePath, locales, language, contentId, workId } = extractParams(token, pathname)
88
let variables: any = { relativePath, locales: locales as Locales, language, statusEqual: "Published" };
99
if (isEditOrPreviewMode() && token) {
1010
variables = workId === undefined
@@ -16,7 +16,7 @@ const generateGQLQueryVars = (token: string, pathname: string): any => {
1616
}
1717

1818
const generateGQLSearchQueryVars = (token: string, pathname: string, searchParam: string | null, sortOption: string, ranking: Ranking = Ranking.Relevance): any => {
19-
const { locales } = extractParams(pathname)
19+
const { locales } = extractParams(token, pathname)
2020
let variables: any = { locales: locales as Locales, searchParam: searchParam, order: sortOption, ranking: ranking };
2121
if (isEditOrPreviewMode() && token) {
2222
variables = { locales: locales as Locales, searchParam, sortOption, ranking };

samples/musicfestival-frontend-react/src/helpers/urlHelper.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import {Ranking} from "../generated";
2+
import { Buffer } from "buffer";
3+
import { Payload } from "../models/Payload";
4+
25

36
const isEditOrPreviewMode = () => {
47
const params = window.location.search.split(/[&?]+/);
@@ -14,10 +17,11 @@ const getImageUrl = (path = "") => {
1417
return path.startsWith("http") ? path : siteUrl + path
1518
}
1619

17-
const extractParams = (urlPath: string) => {
20+
const extractParams = (token: string, urlPath: string) => {
21+
const base64String = token.substring(token.indexOf('.') + 1, token.lastIndexOf('.'));
22+
const payload: Payload = JSON.parse(Buffer.from(base64String, 'base64').toString());
23+
1824
let relativePath = (urlPath.length > 1 && urlPath != "/search") ? urlPath : '/en'
19-
let contentId
20-
let workId = undefined
2125

2226
const epiContentPrefix = "/EPiServer/CMS/Content/";
2327
if (relativePath.startsWith(epiContentPrefix)) {
@@ -29,13 +33,6 @@ const extractParams = (urlPath: string) => {
2933
}
3034

3135
if (relativePath.includes(",")) {
32-
const [, , idString] = relativePath.split(",")
33-
if (idString.includes("_")) {
34-
[contentId, workId] = idString.split("_").map(x => parseInt(x));
35-
36-
} else {
37-
contentId = parseInt(idString)
38-
}
3936
relativePath = relativePath.substring(0, relativePath.indexOf(','));
4037
}
4138

@@ -46,7 +43,7 @@ const extractParams = (urlPath: string) => {
4643
const urlSegments = relativePath.split('/')
4744
const language = urlSegments.length ? urlSegments.find(s => s.length === 2) : "en"
4845

49-
return {relativePath, locales: language, language, contentId, workId}
46+
return { relativePath, locales: language, language, contentId: parseInt(payload.c_id.toString()) , workId: parseInt(payload.c_ver.toString()) }
5047
}
5148

5249
const getRankingFromSearchParams = (searchParams: URLSearchParams): Ranking => {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface Payload {
2+
c_id: number;
3+
c_ver: number;
4+
}

samples/musicfestival-frontend-react/src/pages/SearchPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { subcribeContentSavedEvent } from "../helpers/contentSavedEvent";
2121

2222
let previousSavedMessage: any = null;
2323
const singleKeyUrl = process.env.REACT_APP_CONTENT_GRAPH_GATEWAY_URL as string
24-
const hmacKeyUrl = process.env.REACT_APP_CG_PROXY_URL as string
24+
const hmacKeyUrl = process.env.REACT_APP_CG_CONTENT_URL as string
2525

2626
function SearchPage() {
2727
console.log("Start")

0 commit comments

Comments
 (0)