| 1 |
# Layout Customization |
| 2 |
|
| 3 |
openvpn-auth-oauth2 supports custom templates for the login page. |
| 4 |
The template must a valid Go Template file. |
| 5 |
After rendering, valid HTML must be returned. |
| 6 |
|
| 7 |
The default template can be found here: |
| 8 |
[index.gohtml](https://github.com/jkroepke/openvpn-auth-oauth2/blob/main/internal/ui/index.gohtml) |
| 9 |
|
| 10 |
Available variables: |
| 11 |
|
| 12 |
- `{{.title}}`: `Access denied` or `Access granted` |
| 13 |
- `{{.message}}`: Potential error message or success message |
| 14 |
- `{{.errorID}}`: ErrorID of an error, if present |
| 15 |
- `{{.clientConfigProfiles}}`: List of available profiles, used to render the profile selection screen. |
| 16 |
- `{{.token}}`: An encrypted token to identify the user session, used for profile selection. |
| 17 |
|
| 18 |
The [Go HTML template engine](https://pkg.go.dev/html/template) is used to |
| 19 |
render the HTML file. Template values are contextually escaped before they are |
| 20 |
written to the rendered HTML. |
| 21 |
|
| 22 |
## Client Profile Selector |
| 23 |
|
| 24 |
If the [Client Profile Selector](Client%20specific%20configuration.md#client-profile-selector) is enabled and multiple |
| 25 |
profiles are available for the user, a profile selection screen is shown. The custom template must handle this case by itself. |
| 26 |
|
| 27 |
Minimal example to render the profile selector: |
| 28 |
|
| 29 |
```gotemplate |
| 30 |
{{- if .clientConfigProfiles }} |
| 31 |
<div class="profile-buttons"> |
| 32 |
<form method="POST" action="./profile-submit" class="profile-form"> |
| 33 |
<input type="hidden" name="token" value="{{ .token }}"> |
| 34 |
{{- range .clientConfigProfiles }} |
| 35 |
<input class="profile-button" type="submit" name="profile" value="{{ . }}"> |
| 36 |
{{- end }} |
| 37 |
</form> |
| 38 |
</div> |
| 39 |
{{- end }} |
| 40 |
``` |
| 41 |
|
| 42 |
The default style uses CSS classes to style the profile selector: |
| 43 |
- `profile-buttons`: Container for the profile buttons |
| 44 |
- `profile-form`: Form containing the profile buttons |
| 45 |
- `profile-button`: Individual profile button |
| 46 |
|
| 47 |
## Overriding the default assets |
| 48 |
|
| 49 |
To override the default assets, you can configure `http.assets-path` with the path to the directory containing the assets. |
| 50 |
|
| 51 |
The default assets: |
| 52 |
|
| 53 |
- `style.css`: CSS file to enrich the default layout. By default, it is empty. |
| 54 |
- `mvp.css`: [MVP](https://github.com/andybrewer/mvp) CSS framework |
| 55 |
- `favicon.svg`: Favicon of the login page |
| 56 |
- `i18n.js`: Localization script |
| 57 |
- `i18n/<lang>.json`: Language specific localization file. <lang> is the language code, e.g., `en` for English. |
| 58 |
See [de.json](https://github.com/jkroepke/openvpn-auth-oauth2/blob/main/internal/ui/static/i18n/de.json) for an example. |
| 59 |
|
| 60 |
Alternatively, you link additional assets via external locations inside your custom template. |
| 61 |
|
| 62 |
## Custom localization |
| 63 |
|
| 64 |
If you want to provide custom localization, you have to configure `http.assets-path` first. In the assets directory, |
| 65 |
create a new directory named `i18n` and put your localization files in there. The filename must be the language code |
| 66 |
followed by `.json`. For example, `en.json` for English. |
| 67 |
|
| 68 |
Instead, providing a custom localization file locally, think about to submit a pull request to the project to provide |
| 69 |
the localization for everyone. |