Skip to content

Commit

Permalink
Add HTML support to fce endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
elsand committed Nov 5, 2024
1 parent 3b1faa9 commit 8f047eb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 25 deletions.
74 changes: 51 additions & 23 deletions Controllers/FrontChannelEmbedController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,64 @@ namespace Digdir.BDB.Dialogporten.ServiceProvider.Controllers;
public class FrontChannelEmbedController : ControllerBase
{
[HttpGet]
public IActionResult Get()
public IActionResult Get([FromQuery] bool html = false)
{
var sb = new StringBuilder();
foreach (var claim in User.Claims)
{
sb.AppendLine($"* {claim.Type}: {claim.Value}");
}

return html ? HtmlContent(sb.ToString()) : MarkdownContent(sb.ToString());


}

private IActionResult MarkdownContent(string claims)
{
return Content(
$"""
# Hello from FrontChannelEmbed
This is a paragraph with some text, using Markdown. [Here is a link](https://www.example.com). Here is some additional text.
* Item 1
* Item 2
* Item 3
## Subsection
This is some more text. Lorem ipsum dolor sit amet, consectetur adipiscing elit sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
## Another subsection
Lorem ipsum dolor sit amet, consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et
dolore
## Dialog token
{claims}
""", "text/markdown");
}

private IActionResult HtmlContent(string claims)
{
return Content(
$"""
# Hello from FrontChannelEmbed
This is a paragraph with some text. [Here is a link](https://www.example.com). Here is some additional text.
* Item 1
* Item 2
* Item 3
## Subsection
This is some more text. Lorem ipsum dolor sit amet, consectetur adipiscing elit sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
## Another subsection
Lorem ipsum dolor sit amet, consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et
dolore
## Dialog token
{sb}
""", "text/markdown");
<h1>Hello from FrontChannelEmbed</h1>
<p>This is a paragraph with some text. <a href='https://www.example.com'>Here is a link</a>. Here is some additional text.</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<h2>Subsection</h2>
<p>This is some more text. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<h2>Another subsection</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<h2>Dialog token</h2>
<pre>{claims}</pre>
""", "text/html");
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ GET {baseUrl}/attachment/my-document.docx

### Front Channel Embeds (FCEs)

Front channel embeds are akin to "iframes" that can be embedded in the dialog frontend. The FCEs are loaded using a GET request, using a dialog token and the content is returned is markdown, which then the frontend should map to HTML and render.
Front channel embeds are akin to "iframes" that can be embedded in the dialog frontend. The FCEs are loaded using a GET request, using a dialog token and the content is returned is markdown, which then the frontend should map to HTML and render. An option to return HTML directly also exists, by setting the `html` query parameter to `true`.

The endpoint expects a dialog token to be provided in the `Authorization: Bearer` header. If the token is missing, the request will be rejected with a 403 Forbidden response. This endpoints supports CORS pre-flights, and allows all origins and methods.

No parameters are supported for this endpoint.

Example:
```
GET {baseUrl}/fce
GET {baseUrl}/fce?html=false
```

### Current limitations
Expand Down

0 comments on commit 8f047eb

Please sign in to comment.