Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hdacloud
dex
Commits
d458e882
Unverified
Commit
d458e882
authored
5 years ago
by
Marc-André Dufresne
Browse files
Options
Downloads
Patches
Plain Diff
Allow arbitrary data to be passed to templates
parent
6ae11a1c
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Documentation/templates.md
+24
-0
24 additions, 0 deletions
Documentation/templates.md
cmd/dex/config_test.go
+13
-0
13 additions, 0 deletions
cmd/dex/config_test.go
server/server.go
+4
-0
4 additions, 0 deletions
server/server.go
server/templates.go
+2
-0
2 additions, 0 deletions
server/templates.go
with
43 additions
and
0 deletions
Documentation/templates.md
0 → 100644
+
24
−
0
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
This diff is collapsed.
Click to expand it.
cmd/dex/config_test.go
+
13
−
0
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"
,
...
...
This diff is collapsed.
Click to expand it.
server/server.go
+
4
−
0
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
)
...
...
This diff is collapsed.
Click to expand it.
server/templates.go
+
2
−
0
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
...
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment