fix querying claim data on the dashboard (#1560)

This commit is contained in:
Caleb Doxsey 2020-10-29 10:49:02 -06:00 committed by GitHub
parent 93c257259e
commit 10b5c5ca0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 39 deletions

File diff suppressed because one or more lines are too long

View file

@ -12,8 +12,8 @@
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
<h2>Current user</h2> <h2>Current user</h2>
{{if .User.Claims.picture }} {{with .User.GetClaim "picture"}}
<img class="icon" src="{{.User.GetClaim "picture"}}" alt="user image" /> <img class="icon" src="{{.}}" alt="user image" />
{{else}} {{else}}
<img <img
class="icon" class="icon"
@ -27,68 +27,74 @@
<section> <section>
<p class="message">Your current session details.</p> <p class="message">Your current session details.</p>
<fieldset> <fieldset>
{{if .RedirectURL}} {{with .RedirectURL}}
<label> <label>
<span>URL</span> <span>URL</span>
<a href="{{.RedirectURL}}">{{.RedirectURL}}</a> <a href="{{.}}">{{.}}</a>
</label> </label>
{{end}} {{end}}
{{if .User.Name}} {{with .User.Name}}
<label> <label>
<span>Name</span> <span>Name</span>
<input <input
type="text" type="text"
class="field" class="field"
value="{{.User.Name}}" value="{{.}}"
title="{{.User.Name}}" title="{{.}}"
disabled disabled
/> />
</label> </label>
{{else}} {{if .User.Claims.given_name}} {{else}}
<label> {{with .User.GetClaim "given_name"}}
<span>Given Name</span> <label>
<input <span>Given Name</span>
type="text" <input
class="field" type="text"
value="{{.User.GetClaim "given_name"}}" class="field"
title="{{.User.GetClaim "given_name"}}" value="{{.}}"
disabled title="{{.}}"
/> disabled
</label> />
{{end}} {{if .User.Claims.family_name}} </label>
<label> {{end}}
<span>Family Name</span> {{with .User.GetClaim "family_name"}}
<input <label>
type="text" <span>Family Name</span>
class="field" <input
value="{{.User.GetClaim "family_name"}}" type="text"
title="{{.User.GetClaim "family_name"}}" class="field"
disabled value="{{.}}"
/> title="{{.}}"
</label> disabled
{{end}} {{end}} {{if .User.Id}} />
</label>
{{end}}
{{end}}
{{with .User.Id}}
<label> <label>
<span>UserID</span> <span>UserID</span>
<input <input
type="text" type="text"
class="field" class="field"
value="{{.User.Id}}" value="{{.}}"
title="{{.User.Id}}" title="{{.}}"
disabled disabled
/> />
</label> </label>
{{end}} {{if .User.Email}} {{end}}
{{with .User.Email}}
<label> <label>
<span>Email</span> <span>Email</span>
<input <input
type="email" type="email"
class="field" class="field"
value="{{.User.Email}}" value="{{.}}"
title="{{.User.Email}}" title="{{.}}"
disabled disabled
/> />
</label> </label>
{{end}} {{range $i,$_:= .DirectoryGroups}} {{end}}
{{range $i,$_:= .DirectoryGroups}}
<label> <label>
{{if eq $i 0}} {{if eq $i 0}}
<span>Group</span> <span>Group</span>

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
//go:generate statik -src=./assets -include=*.svg,*.html,*.css,*.js -ns web //go:generate go run github.com/rakyll/statik -src=./assets -include=*.svg,*.html,*.css,*.js -ns web
// Package frontend handles the generation, and instantiation of Pomerium's // Package frontend handles the generation, and instantiation of Pomerium's
// html templates. // html templates.

View file

@ -69,3 +69,14 @@ func (x *User) AddClaims(claims identity.FlattenedClaims) {
x.Claims[k] = svs x.Claims[k] = svs
} }
} }
// GetClaim returns a claim.
//
// This method is used by the dashboard template HTML to display claim data.
func (x *User) GetClaim(claim string) []interface{} {
var vs []interface{}
for _, sv := range x.GetClaims()[claim].GetValues() {
vs = append(vs, sv.AsInterface())
}
return vs
}