Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
d458e882
Unverified
Commit
d458e882
authored
Aug 06, 2019
by
Marc-André Dufresne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow arbitrary data to be passed to templates
parent
6ae11a1c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
0 deletions
+44
-0
templates.md
Documentation/templates.md
+25
-0
config_test.go
cmd/dex/config_test.go
+13
-0
server.go
server/server.go
+4
-0
templates.go
server/templates.go
+2
-0
No files found.
Documentation/templates.md
0 → 100644
View file @
d458e882
# Templates
## Using your own templates
Dex supports using your own templates and passing arbitrary data to them to help customize your installation.
Steps:
1.
Copy contents of the
`web`
directory over to a new directory.
2.
Customize the templates as needed, be sure to retain all the existing variables so Dex continues working correctly.
a. Use this syntax
`{{ "your_key" | extra }}`
to use values from
`frontend.extra`
.
3.
Write a theme for your templates in the
`themes`
directory.
4.
Add your custom data to the Dex configuration
`frontend.extra`
.
```yaml
frontend:
dir: /path/to/custom/web
extra:
tos_footer_link: "https://example.com/terms"
client_logo_url: "../theme/client-logo.png"
foo: "bar"
```
5.
Set the
`frontend.dir`
value to your own
`web`
directory.
To test your templates simply run Dex with a valid configuration and go through a login flow.
\ No newline at end of file
cmd/dex/config_test.go
View file @
d458e882
package
main
import
(
"github.com/dexidp/dex/server"
"testing"
"github.com/ghodss/yaml"
...
...
@@ -69,6 +70,12 @@ storage:
connectionTimeout: 3
web:
http: 127.0.0.1:5556
frontend:
dir: ./web
extra:
foo: bar
staticClients:
- id: example-app
redirectURIs:
...
...
@@ -130,6 +137,12 @@ logger:
Web
:
Web
{
HTTP
:
"127.0.0.1:5556"
,
},
Frontend
:
server
.
WebConfig
{
Dir
:
"./web"
,
Extra
:
map
[
string
]
string
{
"foo"
:
"bar"
,
},
},
StaticClients
:
[]
storage
.
Client
{
{
ID
:
"example-app"
,
...
...
server/server.go
View file @
d458e882
...
...
@@ -107,6 +107,9 @@ type WebConfig struct {
// Defaults to "coreos"
Theme
string
// Map of extra values passed into the templates
Extra
map
[
string
]
string
}
func
value
(
val
,
defaultValue
time
.
Duration
)
time
.
Duration
{
...
...
@@ -181,6 +184,7 @@ func newServer(ctx context.Context, c Config, rotationStrategy rotationStrategy)
issuerURL
:
c
.
Issuer
,
issuer
:
c
.
Web
.
Issuer
,
theme
:
c
.
Web
.
Theme
,
extra
:
c
.
Web
.
Extra
,
}
static
,
theme
,
tmpls
,
err
:=
loadWebConfig
(
web
)
...
...
server/templates.go
View file @
d458e882
...
...
@@ -42,6 +42,7 @@ type webConfig struct {
issuer
string
theme
string
issuerURL
string
extra
map
[
string
]
string
}
func
join
(
base
,
path
string
)
string
{
...
...
@@ -140,6 +141,7 @@ func loadTemplates(c webConfig, templatesDir string) (*templates, error) {
"logo"
:
func
()
string
{
return
c
.
logoURL
},
"url"
:
func
(
s
string
)
string
{
return
join
(
c
.
issuerURL
,
s
)
},
"lower"
:
strings
.
ToLower
,
"extra"
:
func
(
k
string
)
string
{
return
c
.
extra
[
k
]
},
}
tmpls
,
err
:=
template
.
New
(
""
)
.
Funcs
(
funcs
)
.
ParseFiles
(
filenames
...
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment