diff --git a/samples/JS.Yarp/Startup.cs b/samples/JS.Yarp/Startup.cs index ac9ba711..8ca4bcc1 100644 --- a/samples/JS.Yarp/Startup.cs +++ b/samples/JS.Yarp/Startup.cs @@ -52,7 +52,17 @@ public void ConfigureServices(IServiceCollection services) { Path = "/anon_api/{**catch-all}" } - }.WithAntiforgeryCheck() + }.WithAntiforgeryCheck(), + new RouteConfig() + { + RouteId = "api_optional_user", + ClusterId = "cluster1", + + Match = new() + { + Path = "/optional_user_api/{**catch-all}" + } + }.WithOptionalUserAccessToken().WithAntiforgeryCheck() }, new[] { diff --git a/samples/JS.Yarp/wwwroot/app.js b/samples/JS.Yarp/wwwroot/app.js index 345db46f..e6d16062 100644 --- a/samples/JS.Yarp/wwwroot/app.js +++ b/samples/JS.Yarp/wwwroot/app.js @@ -54,6 +54,20 @@ async function callUserToken() { } } +async function callOptionalUserToken() { + var req = new Request("/optional_user_api", { + headers: new Headers({ + 'X-CSRF': '1' + }) + }) + var resp = await fetch(req); + + log("API Result: " + resp.status); + if (resp.ok) { + showApi(await resp.json()); + } +} + async function callClientToken() { var req = new Request("/client_api", { headers: new Headers({ @@ -88,6 +102,7 @@ document.querySelector(".login").addEventListener("click", login, false); document.querySelector(".logout").addEventListener("click", logout, false); document.querySelector(".call_user").addEventListener("click", callUserToken, false); +document.querySelector(".call_optional_user").addEventListener("click", callOptionalUserToken, false); document.querySelector(".call_client").addEventListener("click", callClientToken, false); document.querySelector(".call_anon").addEventListener("click", callNoToken, false); diff --git a/samples/JS.Yarp/wwwroot/index.html b/samples/JS.Yarp/wwwroot/index.html index 4a4c1be6..9d9b2057 100644 --- a/samples/JS.Yarp/wwwroot/index.html +++ b/samples/JS.Yarp/wwwroot/index.html @@ -14,9 +14,9 @@

YARP-first client